Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Fix checkbox field #744

Merged
merged 2 commits into from
Oct 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ build:

test:
@./node_modules/.bin/grunt test:local

test-unit:
@./node_modules/.bin/grunt karma

test-e2e:
@./node_modules/.bin/grunt test:local:e2e
63 changes: 28 additions & 35 deletions src/javascripts/ng-admin/Crud/field/maCheckboxField.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
/*global define*/
/**
* Generic edition field
*
* @example <ma-checkbox-field type="text" field="field" value="value"></ma-checkbox-field>
*/
function maCheckboxField() {
return {
scope: {
'field': '&',
'value': '='
},
restrict: 'E',
link: function (scope, element) {
var field = scope.field();
scope.name = field.name();
scope.v = field.validation();
scope.value = !!scope.value;
var input = element.children()[0];
var attributes = field.attributes();
for (var name in attributes) {
input.setAttribute(name, attributes[name]);
}
},
template: `<input type="checkbox" ng-model="value" id="{{ name }}" name="{{ name }}" class="form-control" />`
};
}

define(function (require) {
'use strict';
maCheckboxField.$inject = [];

/**
* Generic edition field
*
* @example <ma-checkbox-field type="text" field="field" value="value"></ma-checkbox-field>
*/
function maCheckboxField() {
return {
scope: {
'field': '&',
'value': '='
},
restrict: 'E',
link: function (scope, element) {
var field = scope.field();
scope.name = field.name();
scope.v = field.validation();
scope.value = !!scope.value;
var input = element.children()[0];
var attributes = field.attributes();
for (var name in attributes) {
input.setAttribute(name, attributes[name]);
}
},
template:
'<input type="checkbox" ng-model="value" id="{{ name }}" name="{{ name }}" class="form-control" />'
};
}

maCheckboxField.$inject = [];

return maCheckboxField;
});
export default maCheckboxField;
4 changes: 2 additions & 2 deletions src/javascripts/ng-admin/Crud/fieldView/BooleanFieldView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
getLinkWidget: () => '<a ng-click="gotoDetail()">' + module.exports.getReadWidget() + '</a>',
getFilterWidget: () => `<ma-choice-field field="::field" value="value" choices="[{value: 'true', label: 'true' }, { value: 'false', label: 'false' }]"></ma-choice-field>`,
getWriteWidget: () => `<div class="row">
<ma-choice-field class="col-sm-4 col-md-3" ng-if="!field.validation().required" field="::field" value="value"></ma-choice-field>
<ma-checkbox-field class="col-sm-4 col-md-3" ng-if="!!field.validation().required" field="::field" value="value"></ma-checkbox-field>
<ma-choice-field class="col-sm-4 col-md-3" ng-if="!field.validation().required" field="::field" value="$parent.value"></ma-choice-field>
<ma-checkbox-field class="col-sm-4 col-md-3" ng-if="!!field.validation().required" field="::field" value="$parent.value"></ma-checkbox-field>
</div>`
}
24 changes: 22 additions & 2 deletions src/javascripts/test/e2e/EditionViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,30 @@ describe('EditionView', function () {
browser.get(browser.baseUrl + '#/tags/edit/5');
});

it('should render as a checkbox field', function () {
it('should render as a checkbox field when required', function () {
$$('.ng-admin-field-published input[type="checkbox"]')
.then(function(checkboxes) {
expect(checkboxes.length).toBe(1);
return checkboxes[0];
})
.then(function(checkbox) {
expect(checkbox.getAttribute('checked')).toBe('true');
return checkbox.click();
})
.then(function() {
return $$('button[type="submit"]').first().click();
})
.then(function() {
return $$('#page-wrapper .btn-default').first().click();
})
.then(function() {
return $$('.ng-admin-column-actions .btn-xs').get(1).click();
})
.then(function() {
return $$('.ng-admin-field-published input[type="checkbox"]').first();
})
.then(function(checkbox) {
expect(checkbox.length).toBe(1);
expect(checkbox.getAttribute('checked')).toBe(null);
})
});
})
Expand Down