Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattmcginnis/f43cad40d4ca8d95a94549840821373c to your computer and use it in GitHub Desktop.
Save mattmcginnis/f43cad40d4ca8d95a94549840821373c to your computer and use it in GitHub Desktop.
Ember CP Validations - Disabled Bug
import Ember from 'ember';
import { buildValidations, validator } from 'ember-cp-validations';
const Validations = buildValidations({
'something.stepOneValue': validator('presence', {
presence: true,
disabled: Ember.computed.not('model.isStepOne'),
message: 'stepOne value cannot be blank'
}),
'something.stepTwoValue': validator('presence', {
presence: true,
disabled: Ember.computed.not('model.isStepTwo'),
message: 'stepTwo value cannot be blank'
}),
'something.stepThreeValue': validator('presence', {
presence: true,
disabled: Ember.computed.not('model.isStepThree'),
message: 'stepThree value cannot be blank'
})
});
export default Ember.Controller.extend(Validations, {
appName: 'Ember Twiddle',
showErrors: false,
isStepOne: Ember.computed.equal('step', 1),
isStepTwo: Ember.computed.equal('step', 2),
isStepThree: Ember.computed.equal('step', 3),
actions: {
moveStep(direction) {
if (direction === 'next') {
this.incrementProperty('step');
} else {
this.decrementProperty('step');
}
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
setupController(controller, model) {
controller.setProperties({
model: model,
something: Ember.Object.create({
stepOneValue: null,
stepTwoValue: null,
stepThreeValue: null
}),
step: 1
});
}
});
{{#if isStepOne}}
{{boostrap-cp-form
property="something.stepOneValue"
propertyValue=something.stepOneValue
placeholder="Step One Value"
moveStep=(action 'moveStep')
step=step
}}
{{else if isStepTwo}}
{{boostrap-cp-form
property="something.stepTwoValue"
propertyValue=something.stepTwoValue
placeholder="Step Two Value"
moveStep=(action 'moveStep')
step=step
}}
{{else}}
{{boostrap-cp-form
property="something.stepThreeValue"
propertyValue=something.stepThreeValue
placeholder="Step Three Value"
moveStep=(action 'moveStep')
step=step
}}
{{/if}}
<div>
isValid: {{validations.isValid}}<br>
<ul>
{{#each validations.errors as |error|}}
<li>
{{error.message}}
</li>
{{/each}}
</ul>
</div>
<button {{action 'moveStep' 'next'}}>
Next
</button>
<button {{action 'moveStep' 'back'}}>
Back
</button>
<h1>
Step {{step}}
</h1>
<h2>
{{property}}: {{propertyValue}}
<h3>
{{#bs-form formLayout="horizontal" model=this onSubmit=(action moveStep) as |form|}}
{{form.element controlType="text" placeholder=placeholder property=property}}
{{bs-button defaultText="Submit" type="primary" buttonType="submit"}}
{{/bs-form}}
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "2.12.2"
},
"addons": {
"ember-cp-validations": "3.5.3",
"ember-bootstrap": "1.2.2",
"ember-bootstrap-cp-validations": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment