Kdyby / FormsReplicator

Other
30 stars 57 forks source link

setDefaultValue() is not applied #29

Open peterpp opened 10 years ago

peterpp commented 10 years ago

After adding new dynamic container to form, default value of container item is not applied.

Example:

$form->addDynamic('users', function (Container $container) {
    $container->addText('name', 'Name')->setDefaultValue("default value");
}, 1);

Value of "name" text input should be be set to "default value", but it is empty.

Ciki commented 10 years ago

Do you know how to solve this?

peterpp commented 10 years ago

No, I'm currently very busy and I have no time to investigate.

Ciki commented 9 years ago

@fprochazka any idea how to solve this?

fprochazka commented 9 years ago

What version of Nette?

Ciki commented 9 years ago

Nette 2.2.2 (revision 8f701b9 released on 2014-06-26)

Ciki commented 9 years ago

have you had time to look at this? or can you point me to the right direction how to fix this?

Ciki commented 9 years ago

@fprochazka can I provide anything for you to ease up process of fixing this? I'd love to fix it (or have it fixed ideally :) ) ASAP. Thanks!

fprochazka commented 9 years ago

The setDefaultValue is a really complicated problem and as a workaround, you should for now do ->setValues() when you're creating new container.

Ciki commented 9 years ago

OK, thanks

foxycode commented 9 years ago

@fprochazka Can you please specify how this is complicated? Maybe I am missing something. I tried to move addComponent from here after Callback::invoke and everything seems to be working fine.

In my opinion, problem is, that addComponent sets parent and therefore check here causes that default value is not set.

If I am right, I can send you pull request.

fprochazka commented 9 years ago

@foxycode it was complicated, because the internals of forms were rapidly changing and I was unable to maintain 100% compatibility. If you can send a pullrequest with testcase I'll be happy to accept it.

foxycode commented 8 years ago

@fprochazka I give up. I tried, but it's really not so easy as I thought.

josefsabl commented 5 years ago

I worked around this issue by using setValue() instead of setDefaultValue(). It is internal. I know. It is more of a hack than a solution. But maybe it helps.

In my opinion, problem is, that addComponent sets parent and therefore check here causes that default value is not set.

From what I see the problem is that the setDefaultValue only sets the value in case the form was not yet submitted, but it obviously is because of the way the replicator works.

foxycode commented 5 years ago

@josefsabl I know and it works ok when you use setValue() in attached() method. I already switched to https://github.com/contributte/forms-multiplier