Giter Site home page Giter Site logo

Comments (3)

rajakhoury avatar rajakhoury commented on July 26, 2024 2

@daftspunk Thanks!

somehow made it work! :))

The problem was from my end not the plugin, as you can see above I am binding the component to a User, here the User is not the Logged in User but the model to update so $this->getUser() expects an input with the user's identifier and the problem was when the uploader submits the files it was missing an input User which is null - so I wrap the uploader component in a form and added a hidden input with the identifier - it works like a charm - here is what I have in case someone needs to do the same.

Component

public function init()
{

	if( !Auth::check() ){
		return;
	}
	
        $this->account      =  Auth::getAccount() ;
	$this->user         =  $this->getUser() ;

	$this->loadUploader();
}

public function getUser()
{
	return Input('user') ? $this->account
			->users()
			->where ( User::getTableName() .'.'. 'code' , '=' , ( int ) Input('user') )
			->first() 
			: null ;
}
public function loadUploader () 
{
	if ( $this->user )
	{

		$component = $this->addComponent(
			'Responsiv\Uploader\Components\FileUploader',
			'fileUploader',
			[
				'deferredBinding'   => false, 
				'fileTypes'         => ".jpg, .jpeg, .png, .pdf, .txt, .doc, .xls, .xlsx, .docx, .csv",
			]
		);
		$component->bindModel('attachments', $this->user );
	}
}
    // Loads a modal with the uploader
public function onGetAttachmentsModal ()
{

	$this->pageCycle();

	return [
		'#attachments-modal' => $this->renderPartial('@attachments', [
			'user'   =>  $this->user,

		])
	];
}

Partial

<div class="row">
	<div class="col-sm-12">
		{{ form_open({ files:  true , model : user  }) }}
			<input type="hidden" name="user" value="{{user.code}}">
			{% component 'fileUploader'  %}
		{{ form_close() }}
	</div>
</div>

from uploader-plugin.

daftspunk avatar daftspunk commented on July 26, 2024 1

Much success!

from uploader-plugin.

daftspunk avatar daftspunk commented on July 26, 2024

You must load it via the page or the layout, that is so the life cycle knows to look for the upload postback. Partials are not able to do this unfortunately.

https://octobercms.com/docs/cms/partials#life-cycle-limitations

from uploader-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.