Skip to content

Commit

Permalink
Merge pull request #87 from matteocng/82-feat-primitive-field-email
Browse files Browse the repository at this point in the history
Fix #82: Primitive Field Type Fields.email(name)
  • Loading branch information
paveltiunov committed Jan 8, 2016
2 parents ca133f2 + 99a3026 commit 4f7b76b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ Primitive fields types are:
* `Fields.attachment(name)`
* `Fields.password(name)`
* `Fields.link(name)`
* `Fields.email(name)`

`Fields.text(name)` is used to define text fields.
If you want to define text field `foo` with 'Foo' label you could write:
Expand Down
12 changes: 12 additions & 0 deletions public/assets/js/allcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ allcountModule.config(["fieldRenderingServiceProvider", function (fieldRendering
controller.$setViewValue(linkValue ? linkValue : undefined);
});
return $compile('<input type="url" ng-model="linkValue" class="form-control">')(scope);
}],
email: [function (value, fieldDescription) {
var link = $('<a></a>');
link.attr('href', 'mailto:' + value);
link.text(value);
return link;
}, function (fieldDescription, controller, updateValue, clone, scope) {
scope.emailValue = controller.$viewValue;
scope.$watch('emailValue', function (emailValue) {
controller.$setViewValue(emailValue ? emailValue : undefined);
});
return $compile('<input type="email" ng-model="emailValue" class="form-control">')(scope);
}]
}
}]);
Expand Down
9 changes: 9 additions & 0 deletions services/js/Fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ exports.link = function (name) {
})
};

exports.email = function (name) {
return new Field({
name: name,
fieldType: {
id: 'email'
}
})
};

function Field(config) {
_.extend(this, config);
}
Expand Down
3 changes: 2 additions & 1 deletion test-fixtures/crud-field-types/crud-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ A.app({
checkbox: Fields.checkbox("Checkbox"),
checkboxArrayField: Fields.checkbox("Checkbox Array", 'checkboxArray'),
password: Fields.password("Password"),
link: Fields.link("Link")
link: Fields.link("Link"),
email: Fields.email("Email")
}
},
Bar: {
Expand Down
3 changes: 2 additions & 1 deletion test/crud-integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ exports.crudFieldTest = function (test) {
checkbox: true,
checkboxArrayField: true,
password: '123',
link: 'http://www.example.com'
link: 'http://www.example.com',
email: 'example@example.com'
};
return crud.createEntity(_.clone(entityToCreate)).then(function (id) {
return crud.readEntity(id).then(function (entity) {
Expand Down

0 comments on commit 4f7b76b

Please sign in to comment.