Knockout-Validation icon indicating copy to clipboard operation
Knockout-Validation copied to clipboard

HTML5 attributes: no error css class applied to validated element in these cases?

Open luisabreu opened this issue 13 years ago • 9 comments

Hello guys.

I've built a small demo which shows the problem: http://jsfiddle.net/luisabreu/WMdLb/5/

It seems like using the html5 required attribute is not enough for getting a validation error when a field is empty. Removing the extend method comment makes it work as expected though.

luisabreu avatar Jan 08 '13 22:01 luisabreu

Your code seems to be working okay for me. It is validating in both cases.

majidkorai avatar Jan 10 '13 13:01 majidkorai

Hello.

but it's not applying the error css style to the textbox. removing the comment from extend method call does end up applying the css class to the textbox...

luisabreu avatar Jan 10 '13 13:01 luisabreu

It is doing so, i mean applying the css, but it looks little diffrent from the one you have used manually.

majidkorai avatar Jan 10 '13 14:01 majidkorai

Well, I've run the jsfiddle sample on several browsers and the only way to get the red border is by removing the commented extend method call. are you saying that running this sample (without re extend call) works in your pc?

luisabreu avatar Jan 10 '13 14:01 luisabreu

remove the required="required" from input element in your html, and also comment out the extend method, now run it and notice the border color of input. Now add the required="required" attribute, leave the extend method commented and run it. compare both the results, you will find something is happening :)

Although i have never used the html5 validation in any project, but it seems like this attribute is using its own builtin styles. It will not apply the apply the styles you have defined in error class.

majidkorai avatar Jan 10 '13 14:01 majidkorai

this might answer your question. http://stackoverflow.com/questions/5478800/override-css-for-html5-form-validation-required-popup

try placing the the mouse over the input field, after adding required attribute on input while extend remains commented. You will see this "Please fill out this field."

majidkorai avatar Jan 10 '13 15:01 majidkorai

ah, now I understand what you're saying :)

Yes, that's the default behavior and I wasn't seeing it because I was using chrome (which doesn't support the html5 validation attributes yet). Now, my problem isn't really the html5 validation and its default beahvior. My question is getting knockout validation library to read validation rules from the input controls and applying the error styles to the input controls which aren't valid. According to the docs, it should be able to build the rules from the attributes (I think it can do this). the problem is that it's not applying the error element style class when you don't make the extend method call (and this can also be seen when you run the sample in IE or opera).

luisabreu avatar Jan 10 '13 15:01 luisabreu

@luisabreu You need to make the observable validatable http://jsfiddle.net/005zfc7c/.

crissdev avatar Nov 26 '14 20:11 crissdev

Updated fiddle http://jsfiddle.net/bL4sysbj/

The actual problem is #520

crissdev avatar Feb 10 '15 20:02 crissdev