Skip to content

Commit

Permalink
Introduces inputWrapperClass, an element which wraps input fields,
Browse files Browse the repository at this point in the history
errors and help texts.
This is needed for columns in bootstrap horizontal from.

Example usage:

```
// routes/application.js
import Ember from 'ember';

export default Ember.Route.extend({
  beforeModel() {
    this.set('inputWrapperClass', 'col-sm-10');
    this.set('labelClass', 'col-sm-2');
    this.set('formClass', 'form-horizontal');
  },
  fmConfig: Ember.inject.service('fm-config')
});
```

You will have a bootstrap horizontal form.

Column offset are not handeled automatically for fields without a label
(fm-checkbox, fm-submit) or if label property is empty. As this seems
to be to much bootstrap specific for this general form-builder libary.

Together with #36
we could make a nice horizontal bootstrap form like this one:
http://getbootstrap.com/css/#forms-horizontal

```
{{#fm-form}}
  {{fm-field label='Email'}}
  {{fm-field label='Password'}}
  {{fm-checkbox label='Remember me' inputWrapperClass='col-sm-10 col-sm-offset-2'}}
  {{#fm-submit inputWrapperClass='col-sm-10 col-sm-offset-2'}}
     Sign in
  {{/fm-submit}}
{{/fm-form}}
```

Of course you should have service configuration set like above.
  • Loading branch information
jelhan committed Nov 20, 2015
1 parent 7030429 commit 380adb2
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 66 deletions.
3 changes: 2 additions & 1 deletion addon/components/fm-checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export default Ember.Component.extend({
if(!Ember.isEmpty(this.get('errors'))) {
return this.get('fmConfig.errorClass');
}
})
}),
inputWrapperClass: Ember.computed.reads('fmConfig.inputWrapperClass')
});
1 change: 1 addition & 0 deletions addon/components/fm-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default Ember.Component.extend({
labelClass: Ember.computed.reads('fmConfig.labelClass'),
textareaClass: Ember.computed.reads('fmConfig.textareaClass'),
wrapperClass: Ember.computed.reads('fmConfig.wrapperClass'),
inputWrapperClass: Ember.computed.reads('fmConfig.inputWrapperClass'),

init: function() {
if(!this.get('optionValuePath')) {
Expand Down
3 changes: 2 additions & 1 deletion addon/components/fm-radio-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export default Ember.Component.extend({
}
}),
radioGroupWrapperClass: Ember.computed.reads('fmConfig.radioGroupWrapperClass'),
labelClass: Ember.computed.reads('fmConfig.labelClass')
labelClass: Ember.computed.reads('fmConfig.labelClass'),
inputWrapperClass: Ember.computed.reads('fmConfig.inputWrapperClass')
});
1 change: 1 addition & 0 deletions addon/components/fm-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default Ember.Component.extend({
init: function() {
this._super(this);
},
inputWrapperClass: Ember.computed.reads('fmConfig.inputWrapperClass')
submitButtonClass: Ember.computed.reads('fmConfig.submitButtonClass'),
wrapperClass: Ember.computed.reads('fmConfig.wrapperClass'),
tagName: 'div'
Expand Down
1 change: 1 addition & 0 deletions addon/services/fm-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default Ember.Service.extend({
wrapperClass: 'form-group',
labelClass: 'control-label',
inputClass: 'form-control',
inputWrapperClass: '',
textareaClass: 'form-control',
selectClass: 'form-control',
formClass: 'form-vertical',
Expand Down
26 changes: 14 additions & 12 deletions addon/templates/components/ember-form-master-2000/fm-checkbox.hbs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<div class='checkbox'>
<div class={{inputWrapperClass}}>
<div class='checkbox'>

<label>
{{input
type='checkbox'
checked=checked
disabled=disabled
name=name
tabindex=tabindex}}
{{label}}
</label>
<label>
{{input
type='checkbox'
checked=checked
disabled=disabled
name=name
tabindex=tabindex}}
{{label}}
</label>

{{fm-errortext errors=errors}}
{{fm-errortext errors=errors}}

</div>
</div>
</div>
74 changes: 38 additions & 36 deletions addon/templates/components/ember-form-master-2000/fm-field.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,45 @@
<label for="{{forAttribute}}" class="{{labelClass}}">{{{label}}}</label>
{{/if}}

{{#if isBasicInput}}
{{fm-input
type=type
value=value
classNameBindings='errorClass inputClass'
maxlength=maxlength
placeholder=placeholder}}
{{/if}}
<div class={{inputWrapperClass}}>
{{#if isBasicInput}}
{{fm-input
type=type
value=value
classNameBindings='errorClass inputClass'
maxlength=maxlength
placeholder=placeholder}}
{{/if}}

{{#if isSelect}}
{{fm-select
content=content
optionValuePath=optionValuePath
optionLabelPath=optionLabelPath
prompt=prompt
value=value
action=(action 'selectAction')
}}
{{/if}}
{{#if isSelect}}
{{fm-select
content=content
optionValuePath=optionValuePath
optionLabelPath=optionLabelPath
prompt=prompt
value=value
action=(action 'selectAction')
}}
{{/if}}

{{#if isTextarea}}
{{fm-textarea
value=value
classNameBindings='errorClass textareaClass'
placeholder=placeholder
rows=rows
cols=cols
maxlength=maxlength
spellcheck=spellcheck
disabled=disabled
}}
{{/if}}
{{#if isTextarea}}
{{fm-textarea
value=value
classNameBindings='errorClass textareaClass'
placeholder=placeholder
rows=rows
cols=cols
maxlength=maxlength
spellcheck=spellcheck
disabled=disabled
}}
{{/if}}

{{#if errors}}
{{fm-errortext errors=errors}}
{{/if}}
{{#if errors}}
{{fm-errortext errors=errors}}
{{/if}}

{{#if helptext}}
{{fm-helptext helptext=helptext}}
{{/if}}
{{#if helptext}}
{{fm-helptext helptext=helptext}}
{{/if}}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<label class='{{labelClass}}'>{{label}}</label>
{{/if}}

{{#each content as |option|}}
<div class={{inputWrapperClass}}>
{{#each content as |option|}}

{{fm-radio content=option}}
{{fm-radio content=option}}

{{/each}}
{{/each}}

{{fm-errortext errors=errors}}
{{fm-errortext errors=errors}}
</div>
22 changes: 12 additions & 10 deletions addon/templates/components/ember-form-master-2000/fm-submit.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<button
value={{value}}
disabled={{disabled}}
class='{{submitButtonClass}}'
type="submit">
{{#if value}}
{{value}}
{{/if}}
{{yield}}
</button>
<div class={{inputWrapperClass}}>
<button
value={{value}}
disabled={{disabled}}
class='{{submitButtonClass}}'
type="submit">
{{#if value}}
{{value}}
{{/if}}
{{yield}}
</button>
</div>
3 changes: 1 addition & 2 deletions tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Ember from 'ember';

export default Ember.Route.extend({

model: function() {
return Ember.RSVP.hash({
exampleModel: Ember.Object.create(),
Expand Down Expand Up @@ -77,4 +76,4 @@ export default Ember.Route.extend({

}

});
});

0 comments on commit 380adb2

Please sign in to comment.