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

Multiple forms on one page validation problem #188

Closed
BernhardBaumrock opened this issue Aug 7, 2018 · 4 comments
Closed

Multiple forms on one page validation problem #188

BernhardBaumrock opened this issue Aug 7, 2018 · 4 comments

Comments

@BernhardBaumrock
Copy link

BernhardBaumrock commented Aug 7, 2018

Version: ?.?.?

Bug Description

There are 2 problems with multiple forms on one page:

  1. if both forms have a field with the same name the input id's will be identical resulting in 2 html elements having the same ID
  2. validating checkboxes with the same name is not possible

Please see this forum post for screenshots and a screencast:
https://forum.nette.org/en/30969-multiple-forms-on-one-page-standalone-version#p198618

Expected Behavior

all fields should have unique names

@dg
Copy link
Member

dg commented Aug 7, 2018

Give name to forms via $form = new Form('first'); and $form = new Form('second');

@BernhardBaumrock
Copy link
Author

BernhardBaumrock commented Aug 7, 2018

thx, sorry the code is misleading! I already did that. The issue that I reported occurs even when I give names to the forms! Please see the screencast in the linked post.

dg added a commit that referenced this issue Aug 7, 2018
…loses #188]

Solution: set Nette\Forms\Controls\BaseControl::$idMask = 'frm-%2$s-%1$s';
@dg dg closed this as completed in 1bff090 Aug 7, 2018
@dg
Copy link
Member

dg commented Aug 7, 2018

I fixed it in code, but for back compatibility you have to set Nette\Forms\Controls\BaseControl::$idMask = 'frm-%2$s-%1$s'; in the beginning of the code.

dg added a commit that referenced this issue Sep 12, 2018
…loses #188]

Solution: set Nette\Forms\Controls\BaseControl::$idMask = 'frm-%2$s-%1$s';
dg added a commit that referenced this issue Sep 12, 2018
…loses #188]

Solution: set Nette\Forms\Controls\BaseControl::$idMask = 'frm-%2$s-%1$s';
@tvape
Copy link

tvape commented Nov 27, 2018

It's funny. I try to upgrade from Nette 2.0 to 2.4 (using mostly forms only) and I am glad I waited so long, because I use multiple forms on one page and in Nette 2.0 it was already implemented - the $idMask then was "frm%s-%s". It means I have to use "frm%2$s-%1$s" today. And I am very happy, that it's working again as it IMHO always should be. The only difference is, that the default implementation now will create errors without manual changing the $idMask, because the $idMask is 'frm-%s'.

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

No branches or pull requests

3 participants