Validate all the things, all the time

This commit is contained in:
John Cowen 2018-06-12 16:22:54 +01:00 committed by Jack Pearkes
parent ee3a32d771
commit f4218b4bea
2 changed files with 4 additions and 2 deletions

View File

@ -40,6 +40,7 @@ export default Controller.extend({
// normalize back to standard event
const target = e.target || { ..._target, ...{ name: e, value: value } };
switch (target.name) {
case 'Description':
case 'Action':
set(this.changeset, target.name, target.value);
break;
@ -60,6 +61,7 @@ export default Controller.extend({
set(this, target.name, selected);
break;
}
this.changeset.validate();
},
},
});

View File

@ -50,13 +50,13 @@
</div>
<label class="type-text{{if item.error.Description ' has-error'}}">
<span>Description</span>
{{input value=item.Description name='description' placeholder="Description"}}
<input type="text" name="Description" value="{{item.Description}}" placeholder="Description" onchange={{action 'change'}} />
<em>Choose a Consul Service, write in a future Consul Service, or write any Service URL</em>
</label>
</fieldset>
<div>
{{#if create }}
<button type="submit" {{ action "create" item}} disabled={{if item.isInvalid 'disabled'}}>Save</button>
<button type="submit" {{ action "create" item}} disabled={{if (or item.isPristine item.isInvalid) 'disabled'}}>Save</button>
{{ else }}
<button type="submit" {{ action "update" item}} disabled={{if item.isInvalid 'disabled'}}>Save</button>
{{/if}}