-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Please provide option to validate form elements like <ion-input>, <ion-select>, <ion-textarea> #6040
Comments
Hello, thanks for opening an issue with us! You can already do form validation in Ionic 2 using the angular 2 forms/formbuilder module. Thats the great thing about Ionic 2, it includes all the awesomeness from Angular 2! Here is a link to the Forms docs on the Angular 2 site: https://angular.io/docs/ts/latest/guide/forms.html Thanks again! |
I actually talking about |
@adamdbradley @brandyscarney Is there a way to validate |
Wanted to point out an issue I've come across using the angular2 formbuilder with an ion-input using the required attribute. If you focus in and then focus out I would expect the input to have the ng-invalid class added, but it doesn't. To summarize:
See also: |
@tlaverdure +1 First:
Second: Update: |
What I have noticed is that For me it would be useful if |
this is to make the native input, ion-input and item all have the same classes for the control references #6040
So there is a lot going on on this issue. I'm going to try to address everything but let me know if there is something I miss. @Dheran: I'm not sure what you are looking for in terms of validation. Could you please explain what you mean? The form validation Angular 2 offers should be what you need but if you could explain more of what you want, I can help more. 😄 @tlaverdure: Thanks for bringing this to our attention. I have fixed this in the repo, and published a nightly version of the framework where it can be tested. Could you please take a look and let me know if you find any issues? To install the nightly version:
If you haven't updated to @xr0master: Thanks for letting me know about the UI issues. I've updated the UI to extend the length of the item and added Sass variables for turning off success/error highlighting:
There is another issue for this (#5052), could you please put any feedback you have for improving success/error highlighting on that issue? @WHarris22 I believe your issue is the same as @tlaverdure mentioned. Please read my above response to him. Here's a gif of my most recent changes: Source code for this is here: Thanks everyone! 😄 |
@brandyscarney Very cool! Can you implement it for ion-select too, please? And can you append ability to change the line color? It'll be amazing. BTW iOS hasn't this validation syntax (bottom line); It will be fixed? Or iOS hasn't validation style? About the another issue (#5052). I think no special about it, any container with ngSwitch directive. Something like a ngMessages directive of md, IMO. You need be carefully with a long text and an animation (changing the error message to another). It'll be cool, if we could disable the animation and change the error text color too. PS Thanks you for your amazing work |
Yes, I'll be working on adding it to the select next. 😄 I'm not sure about adding validation style to iOS, it's something that needs to be discussed. I agree with the ngMessages directive. There has actually been an issue created with that in mind here: #6785 |
@brandyscarney after updating to beta 8, ion-textarea and ion-input adding border bottom automatically. Is there a way to prevent this? |
The highlighting can be turned off via the following Sass variables:
and to change the colors:
The issue is a WIP so please add any feedback on #5052. Thanks! |
As I discussed in this closed issue I think it would be useful to be able to validate inputs inside the alert prompt component. Not sure how you could go about this, but one idea is to have more options under the input option to provide validators and error messages? e.g.
|
Hi, |
Is there any update on making the classes on ion-item for ion-select, etc? And will need to implement some common functionality among all of them... Like the
As well as injecting and implementing NgControl into every input control component. If there is a set way Ionic wants to implement it, I don't want to waste my time doing something that doesn't follow current architecture. So if there is.. any guidance would definitely be appreciated! (: |
@BradyLiles Have you already started to work on this issue? I want to join forces with you. |
ion-select still doesn't work with required attribute |
A bit of a hack, but a quick workaround for me for anything other than <ion-item [class.ng-invalid]="!profileForm.controls.state.valid">
<ion-label stacked>State</ion-label>
<ion-select formControlName="state">
...
</ion-select>
</ion-item> |
ionic is automatically validating the input fields, but it misses to update the parent ion-item if a control is marked as touched (markAsTouched() Method on control) from code. I've a next button which should mark all untouched and invalid controls as invalid (red border). i have to update the parent ion-item style manually like this: html: <form [formGroup]="personForm">
<ion-list>
<ion-item>
<ion-label color="primary">Name</ion-label>
<ion-input type="text" placeholder="Name" [(ngModel)]="username" formControlName="username"></ion-input>
</ion-item>
</ion-list>
</form> code: next()
{
for (var controlName in this.personForm.controls) {
let ele = document.querySelector('[formControlName="' + controlName + '"]');
this.personForm.controls[controlName].markAsTouched();
if(ele) {
this.setControlCss(ele.parentElement.parentElement.parentElement, this.personForm.controls[controlName]);
}
}
}
setControlCss(element: any, control: AbstractControl)
{
this.renderer.setElementClass(element, 'ng-untouched', control.untouched);
this.renderer.setElementClass(element, 'ng-touched', control.touched);
this.renderer.setElementClass(element, 'ng-pristine', control.pristine);
this.renderer.setElementClass(element, 'ng-dirty', control.dirty);
this.renderer.setElementClass(element, 'ng-valid', control.valid);
this.renderer.setElementClass(element, 'ng-invalid', !control.valid);
} EDIT: |
Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. Thank you for using Ionic! |
ionic v2
The text was updated successfully, but these errors were encountered: