Skip to content
This repository has been archived by the owner on Apr 30, 2018. It is now read-only.

No error messages? #5

Open
piernik opened this issue Mar 29, 2015 · 4 comments
Open

No error messages? #5

piernik opened this issue Mar 29, 2015 · 4 comments

Comments

@piernik
Copy link

piernik commented Mar 29, 2015

I see that here are no feedback messages :/ I suppose it's because ionic has none.
How to fiz it? How to add those messages? Can You give simpliest example for required text input?

@mhartington
Copy link
Contributor

Will work on this and have it in the next version 👍

@piernik
Copy link
Author

piernik commented Mar 31, 2015

Thanks - when will You menage to do it?

@kentcdodds
Copy link
Member

Perhaps this example would be helpful.

@c-jacquin
Copy link

Hello,
I made something simple that work here : https://github.com/Charl---/angular-formly-templates-ionic

Thx for the link, it was very helpfull.

The configuration object for a field look like this

{
  ...
  templateOptions: {
  ...
    validate: true,    //display or not the error message section
    validateCustom: 'your url'    //the url of a template with ngMessage
    required: true,
    maxlength: 14,
    minlength: 5,
    ... ,
    validation : {    //default error message, they are replaced by those on the template if defined
      messages: {
        required: (viewValue, modelValue, scope)=> {
          return scope.to.label + ' is required';
        },
        minlength: (viewValue, modelValue, scope)=> {
          return scope.to.minlength + ' character minimum';
        },
        ...
      }
    }
  }
}

the template with ng-message directive must look like this :

<script id="validation-errors.html" type="text/ng-template">
      <div class="error" ng-message="email">
        <i class="ion-information-circled"></i> Invalid email.
      </div>
      <div class="error" ng-message="required">
        <i class="ion-information-circled"></i> Please fill out this field.
      </div>
      <div class="error" ng-message="minlength">
        <i class="ion-information-circled"></i> Damn too short :(.
      </div>
      <div class="error" ng-message="maxlength">
        <i class="ion-information-circled"></i> Maximum number of characters reached relax.
      </div>
   </script>

The div containing the messages is decorated with is-dirty, id-touched, and is-invalid class depending on the field state.

here is a simple codepen demo with some extra style
http://codepen.io/Charl---/pen/yYZpPa

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

No branches or pull requests

4 participants