zend-form icon indicating copy to clipboard operation
zend-form copied to clipboard

Input filters on form elements are not reflected when rendered

Open tylkomat opened this issue 8 years ago • 11 comments

For example setting a form element required in the input filter does not render the element with required attribute. The same happens for any validations which could be directly handled by html5.

I know I can set the attributes on the form element directly, but with this I have to maintain the same information in two separate places.

tylkomat avatar Nov 10 '17 15:11 tylkomat

@tylkomat Right, this is not implement.

If you would like to tackle this, we would appreciate the help.

froschdesign avatar Mar 12 '18 07:03 froschdesign

@tylkomat @froschdesign I ran into the same problem myself so I monkey patched few Form classes that I am now using using in Form builder so they build input attributes within the other Form Input features. I'd like to help with this PR if that's okay with you.

unckleg avatar Mar 12 '18 09:03 unckleg

@unckleg Everyone is welcome!

froschdesign avatar Mar 12 '18 09:03 froschdesign

Do you think it is correct to always automatically add the required attribute if the field is required? Also, side note - sometimes the field is required, but would need a custom message. This is implemented with the NotEmpty validator. Do we need to implement it for the validator, too?

thexpand avatar Aug 11 '18 20:08 thexpand

I am not a big fan of HTML 5 validation mainly because this is not consistant between browsers. Also, Message cannot be customized without javascript (see https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation#Customized_error_messages).

Should ZF automatically set the required HTML attribute, it will take a mean to... get rid of it !

jcaillot avatar Aug 11 '18 20:08 jcaillot

Do you think it is correct to always automatically add the required attribute if the field is required?

Yep

Also, side note - sometimes the field is required, but would need a custom message. This is implemented with the NotEmpty validator. Do we need to implement it for the validator, too?

While I agree that there might be some level of customisation, required being implemented via NotEmpty is a detail, and replacing the NotEmpty validator is different from just using required.

Ocramius avatar Aug 12 '18 07:08 Ocramius

@Ocramius Offtopic: Maybe we should think of a way of customizing the required message, because the current way of doing it via the NotEmpty validator is just a workaround. What do you think?

thexpand avatar Aug 12 '18 09:08 thexpand

Not really needed for ghe HTML required attribute: browsers are generally quite clear on it

On Sun, 12 Aug 2018, 12:33 Cvetomir, [email protected] wrote:

@Ocramius https://github.com/Ocramius Offtopic: Maybe we should think of a way of customizing the required message, because the current way of doing it via the NotEmpty validator is just a workaround. What do you think?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zendframework/zend-form/issues/182#issuecomment-412330435, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakPvMQiSYqDw6ub2VtzSN_2rDsBpTks5uP_ZtgaJpZM4QZtOH .

Ocramius avatar Aug 12 '18 09:08 Ocramius

I meant customizing the message after the validation process in the back-end (when $form->isValid() is called), hence I added the 'offtopic'. Otherwise, I'm okay with adding the HTML5 attribute. I will investigate and try to make a PR about it.

thexpand avatar Aug 12 '18 09:08 thexpand

That can be customised by replacing the NotEmpty validator

On Sun, 12 Aug 2018, 12:45 Cvetomir, [email protected] wrote:

I meant customizing the message after the validation process in the back-end (when $form->isValid() is called), hence I added the 'offtopic'. Otherwise, I'm okay with adding the HTML5 attribute. I will investigate and try to make a PR about it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zendframework/zend-form/issues/182#issuecomment-412330988, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakAEQ46GnURojSWKU3TiJ2LgdCECWks5uP_k8gaJpZM4QZtOH .

Ocramius avatar Aug 12 '18 10:08 Ocramius

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at https://github.com/laminas/laminas-form/issues/9.

weierophinney avatar Dec 31 '19 22:12 weierophinney