Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

validate field without required attribute #90

Open
zztop101 opened this issue Aug 18, 2016 · 2 comments
Open

validate field without required attribute #90

zztop101 opened this issue Aug 18, 2016 · 2 comments

Comments

@zztop101
Copy link

zztop101 commented Aug 18, 2016

Hi,

How can I validate email address when there is no "required" attribute

This does not display invalid email:
<input type="email" class="form-control" placeholder="Email" ng-model="formData.email" >

This displays invalid email but field is required, when I want it optional.
<input type="email" class="form-control" placeholder="Email" ng-model="formData.email" required >

I tried this which is a step closer, However when the form initially appears it is already ticked. It does not seem to matter what is the ng-required field.

<input type="email" class="form-control" placeholder="Email" ng-model="formData.email" ng-required="formData.email.length > 0" >

@johannesjo
Copy link
Owner

johannesjo commented Aug 18, 2016

Hello @zztop101! Thank you for reporting the issue. I find it a little weird, because this worked just fine before. My first guess is that this is a bug with angular itself, as somehow the ng-valid-required class is applied initially when using ng-required:
http://plnkr.co/edit/8g37JSSaxb4F5GsWGPbz?p=preview
http://plnkr.co/edit/nqPhJkmag3AQdntFRbEN?p=preview (without ngFabForm)

@zztop101
Copy link
Author

zztop101 commented Aug 18, 2016

Hi,
if you add ng-required="!required" it will not have the green tick when it loads initially.
However, if you type in the field then remove what you type, it will then come up as "required field".
According to the quote below, I don't think you can use ng-required. Maybe you need to add a new directive to fab-forms.

The ng-required directive is necessary to be able to shift the value between true and false. In HTML, you cannot set the required attribute to false (the presence of the required attribute makes the element required, regardless of its value).

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

No branches or pull requests

2 participants