Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Issue #113
Browse files Browse the repository at this point in the history
Not rendered: frontile forms ChangesetForm
  • Loading branch information
hotsoft-desenv4 committed Jan 6, 2021
1 parent a8f6c18 commit 61ad013
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
42 changes: 13 additions & 29 deletions app/components/centro-custos/centro-custos-form.hbs
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
{{#if @model}}
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">
Nome:
</label>
<div class="col-sm-6">
<Input @type="text" @value={{@model.nome}} class="form-control" placeholder="Centro custo" autofocus/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">
Versão:
</label>
<div class="col-sm-6">
<Input @type="text" @value={{@model.version}} class="form-control" placeholder="Versão" autofocus/>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success" {{on "click" (fn this.save @model)}}>
Salvar
</button>
</div>
</div>
</div>
{{else}}
Regsitro não Encontrado
{{/if}}
{{#let (changeset this.myFormModel this.myValidations) as |changesetObject|}}
<ChangesetForm @changeset={{changesetObject}} as |Form changeset|>
<Form.Input @fieldName="name.first" @label="First Name" />
<Form.Input @fieldName="name.last" @label="Last Name" />
<Form.Input @fieldName="email" @label="Email" />
<Form.Input @fieldName="hometown" @label="Home Town" />
<Form.Select @fieldName="preferences" @label="Preferences" />

<button type="submit">
Submit
</button>
</ChangesetForm>
{{/let}}
27 changes: 27 additions & 0 deletions app/components/centro-custos/centro-custos-form.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import DefaultComponent from '../default/default';
import { Changeset } from 'ember-changeset';
import lookupValidator from 'ember-changeset-validations';
import validatePresence from 'ember-changeset-validations/validators/presence';

export default class CentroCustosFormComponent extends DefaultComponent {
@tracked redirectTo = '/centro_custos';
@tracked modelString = 'centro_custo';

myFormModel = {
name: {
first: 'Ron',
last: 'Swanson'
},
email: '[email protected]',
hometown: 'Pawnee, IN',
preferences: ['Lagavulin', 'Steak', 'Bacon', 'No govt.']
};

validations = {
myValue: validatePresence(true)
};

myModel = {
myValue: ''
};

myChangeset = new Changeset(
this.myModel,
lookupValidator(this.validations),
this.validations
);

@action
save(model, ...event) {
super.save(model, ...event);
Expand Down

0 comments on commit 61ad013

Please sign in to comment.