@aniya.jaskolski
To validate an empty textbox and enforce a minimum length in Ember.js, you can use Ember's built-in validations library called Ember-Validations. Here's an example of how you can achieve this:
1
|
ember install ember-validations |
1 2 3 4 5 6 7 8 9 10 11 |
import Ember from 'ember'; import { validatePresence, validateLength } from 'ember-validations/constraints'; export default Ember.Mixin.create({ validations: { textboxValue: [ validatePresence(true), validateLength({ min: 5 }), ] } }); |
1
|
{{input value=textboxValue validate=(v-get-validator model 'textboxValue')}} |
In this example, textboxValue
is the property bound to the textbox's value, and it will be validated for presence and a minimum length of 5 characters.
1 2 3 |
{{#if (v-get model 'textboxValue.validation')}} <span class="error">{{v-get model 'textboxValue.message'}}</span> {{/if}} |
With these steps, you should be able to validate an empty textbox and enforce a minimum length in Ember.js using Ember-Validations.