WebChemistry / images

Image storage for Nette Framework
36 stars 20 forks source link

$form->setDefaults(...) from presenter action does not work on image upload #11

Closed JanMikes closed 7 years ago

JanMikes commented 8 years ago

Working example:

$form>addImageUpload("image", "Image")
    ->setDefaultValue("xxx.jpg");

Example that does not work:

// MyPresenter.php
public function actionEdit()
{
    $this["myForm"]->setDefaults([
        "image" => "xxx.jpg",
    ]);
}

I am not sure if it is intended to not work (unable to make it work because of $form->setDefaults() implementation or it is just a bug.

MartkCz commented 8 years ago

It's problem with https://api.nette.org/2.4/source-Forms.Container.php.html#44 => setDefaults is not called after submit and UploadControl needs default value for delete of previous image (I can write commit, which fix displaying image, but it don't solve main problem).

The solutions: 1) Create hidden text input with image name. 2) Use this:

// MyPresenter.php
public function actionEdit()
{
    $this["myForm"]->setDefaults([
        "image" => "xxx.jpg",
    ]);
    $this["myForm"]->setValue('xxx.jpg');
}