Skip to content

Commit

Permalink
Removed Easy form precompiled templates for compatibility with handle…
Browse files Browse the repository at this point in the history
…bars 2.0
  • Loading branch information
Duncan Graham Walker committed Feb 14, 2015
1 parent 048b893 commit 89e6ff7
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 282 deletions.
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ export default Ember.View.extend(
return new Ember.RSVP.Promise(function(resolve, reject) {
// Do something unusual here, then resolve.

resolve();
this.showCoolAnimation();

if (!this.get('someViewProperty')) {
reject(); // Resets the form submission state
} else {
resolve(); // Will call the controller method
}
});
}

Expand Down Expand Up @@ -167,6 +173,31 @@ export default Ember.ObjectController.extend(

The saving mixin will handle all internals including the state of the form (submitted or not submitted) and running the validations - you just have to specify what you want to happen when validations have been run.

You can also add a destroy method:

```js
// app-name/controllers/post/edit.js

import Ember from 'ember';
import Saving from 'ember-easy-form-extensions/mixins/controllers/saving';

export default Ember.ObjectController.extend(
Saving, {

destroy: function() {
var _this = this;

// Runs when the user clicks on the destroy submission component after the view has handled the destroy action and checked to see if you've specified a destroyHandler in the view
_this.get('content').destroyRecord().then(function() {
_this.transitionToRoute('posts');
});
}

});
```

Please note, this is best used when you're deleting a persisted model, not a new one - in the latter situation consider using [the delete record mixin](#delete-record).

The `Saving` mixin also provides support for automatically revalidating your model when you're using a computed property with `ember-validations`. Just add the computed property names to the `revalidateFor` array:

```js
Expand All @@ -190,7 +221,7 @@ export default Ember.ObjectController.extend(
}

required: function() {
return somethingElse && !anotherThing;
return this.get('somethingElse') && !this.get('anotherThing');
}.property('somethingElse', 'anotherThing'),

cancel: function() {},
Expand All @@ -201,7 +232,7 @@ export default Ember.ObjectController.extend(

If your routes follow a RESTful naming convention, you can take advantage of two new **boolean** properties on the controller:
- `new` - True if the route is for a new model (e.g. `this.route('new')`;)
- 'editing' - True if the route is for editing a model (e.g. `this.route('edit');`)
- `editing` - True if the route is for editing a model (e.g. `this.route('edit');`)

You can use these to set the button text, for example:

Expand Down Expand Up @@ -322,7 +353,7 @@ To customize the template, just override the path at `app-name/templates/compone

The loading spinner component replaces the buttons in your submission components when the form has been submitted.

If you already have a spinner component simply export it at the correct path:
If you already have a spinner component simply export it at the correct path to immediately use your component:

```js
// app-name/components/loading-spinner.js
Expand All @@ -340,6 +371,8 @@ Alternatively, just add your spinner to the template:
<img src="some-non-css-spinner.gif">
```

If you really don't want to use the `{{loading-spinner}}` component anywhere in your app, edit the submission component templates as described in [template customization](#template-customization).

## Helpers

`ember-easy-form-extensions` comes prepackaged with **scopeless** block template helpers. These helpers make it really easy to code semantic forms and keep your code maintainable.
Expand Down
24 changes: 14 additions & 10 deletions addon/initializers/easy-form-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import form from 'ember-easy-form-extensions/helpers/form';
import formControls from 'ember-easy-form-extensions/helpers/form-controls';

export function initialize(/* container, app */) {
var EasyForm = Ember.EasyForm;
var Handlebars = Ember.Handlebars;
var run = Ember.run;

Expand All @@ -20,27 +19,34 @@ export function initialize(/* container, app */) {
Default option overrides
*/

EasyForm.Config.registerWrapper('default', {
Ember.EasyForm.Config.registerWrapper('default', {
errorClass: 'error',
errorTemplate: 'easy-form/error',

formClass: 'form',
fieldErrorClass: 'control-error',

hintClass: 'hint',
hintTemplate: 'easy-form/hint',

inputClass: 'control',
inputTemplate: 'easy-form/input',

labelClass: 'label',
labelTemplate: 'easy-form/label'
});

EasyForm.Checkbox.reopen({
Ember.EasyForm.Checkbox.reopen({
classNames: ['input-checkbox'],
});

EasyForm.TextField.reopen({
Ember.EasyForm.TextField.reopen({
attributeBindings: ['dataTest:data-test'],
classNames: ['input'],
dataTest: Ember.computed.alias('parentView.dataTest'),
});

EasyForm.TextArea.reopen({
Ember.EasyForm.TextArea.reopen({
attributeBindings: ['dataTest:data-test'],
classNames: ['input-textarea'],
dataTest: Ember.computed.alias('parentView.dataTest'),
Expand All @@ -55,7 +61,7 @@ export function initialize(/* container, app */) {
If a label is specified on the input, this will be used in place of the property name.
*/

EasyForm.Error.reopen({
Ember.EasyForm.Error.reopen({
errorText: function() {
var propertyName = this.get('parentView.label') || this.get('property') || '';

Expand All @@ -67,10 +73,8 @@ export function initialize(/* container, app */) {
Temporarily binds a success class the the control when the input goes from invalid to valid.
*/

EasyForm.Input.reopen({
classNameBindings: ['showValidity:input_with_validity'],
datepickerInputId: insert('elementId', 'input-{{value}}'),
isDatepicker: Ember.computed.equal('as', 'date'),
Ember.EasyForm.Input.reopen({
classNameBindings: ['showValidity:control-valid'],
showValidity: false,

setInvalidToValid: function() {
Expand Down
1 change: 1 addition & 0 deletions app/templates/easy-form/error.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{view.errorText}}
1 change: 1 addition & 0 deletions app/templates/easy-form/hint.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{view.hintText}}
15 changes: 15 additions & 0 deletions app/templates/easy-form/input-controls.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{input-field
propertyBinding='view.property'
inputOptionsBinding='view.inputOptionsValues'
}}

{{#if view.showError}}
{{error-field propertyBinding='view.property'}}
{{/if}}

{{#if view.hint}}
{{hint-field
propertyBinding='view.property'
textBinding='view.hint'
}}
{{/if}}
2 changes: 1 addition & 1 deletion app/templates/easy-form/input.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{label-field propertyBinding='view.property' textBinding='view.label'}}

<div class="input_wrapper">
{{partial 'easyForm/inputControls'}}
{{partial 'easy-form/input-controls'}}
</div>
1 change: 1 addition & 0 deletions app/templates/easy-form/label.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{view.labelText}}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-easy-form-extensions",
"version": "0.1.0",
"description": "Extends Ember EasyForm into the view and controller layers of your Ember CLI app to provide easy event and action handling using mixins and components",
"version": "0.1.1",
"description": "Extends Ember EasyForm into the view and controller layers of your Ember CLI app to provide easy event and action handling using mixins and components.",
"directories": {
"doc": "doc",
"test": "tests"
Expand Down
104 changes: 0 additions & 104 deletions vendor/ember-easy-form-extensions.js

This file was deleted.

Loading

0 comments on commit 89e6ff7

Please sign in to comment.