Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setDefaultValue() is not applied #29

Open
peterpp opened this issue May 27, 2014 · 14 comments
Open

setDefaultValue() is not applied #29

peterpp opened this issue May 27, 2014 · 14 comments
Labels

Comments

@peterpp
Copy link

peterpp commented May 27, 2014

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.

@fprochazka fprochazka added the bug label Jun 7, 2014
@Ciki
Copy link

Ciki commented Jun 13, 2014

Do you know how to solve this?

@peterpp
Copy link
Author

peterpp commented Jun 18, 2014

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

@Ciki
Copy link

Ciki commented Oct 14, 2014

@fprochazka any idea how to solve this?

@fprochazka
Copy link
Member

What version of Nette?

@Ciki
Copy link

Ciki commented Oct 14, 2014

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

@Ciki
Copy link

Ciki commented Oct 18, 2014

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

@Ciki
Copy link

Ciki commented Nov 3, 2014

@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
Copy link
Member

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

@Ciki
Copy link

Ciki commented Nov 3, 2014

OK, thanks

@foxycode
Copy link
Contributor

foxycode commented Jun 2, 2015

@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
Copy link
Member

@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
Copy link
Contributor

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

@josefsabl
Copy link

josefsabl commented May 20, 2019

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants