-
Notifications
You must be signed in to change notification settings - Fork 724
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] Required boolean fields use a checkbox for edition instad of a dropdown #707
Changes from all commits
8c635a1
2fc3d96
b8a1b8f
981509b
c2abaf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
module.exports = { | ||
getReadWidget: () => '<ma-boolean-column value="::entry.values[field.name()]"></ma-boolean-column>', | ||
getLinkWidget: () => '<a ng-click="gotoDetail()">' + module.exports.getReadWidget() + '</a>', | ||
getLinkWidget: () => '<a ng-click="gotoDetail()">' + module.exports.getReadWidget() + '</a>', | ||
getFilterWidget: () => `<ma-choice-field field="::field" value="values[field.name()]" 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" field="::field" value="entry.values[field.name()]"></ma-choice-field></div>` | ||
getWriteWidget: () => `<div class="row"> | ||
<ma-choice-field class="col-sm-4 col-md-3" ng-if="!field.validation().required" field="::field" value="entry.values[field.name()]"></ma-choice-field> | ||
<ma-checkbox-field class="col-sm-4 col-md-3" ng-if="!!field.validation().required" field="::field" value="entry.values[field.name()]"></ma-checkbox-field> | ||
</div>` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*global angular,inject,describe,it,expect,beforeEach*/ | ||
describe('directive: ma-boolean-column', function () { | ||
'use strict'; | ||
|
||
var directive = require('../../../../ng-admin/Crud/column/maBooleanColumn'); | ||
var BooleanField = require('admin-config/lib/Field/BooleanField'); | ||
|
||
angular.module('testapp_BooleanColumn', []).directive('maBooleanColumn', directive); | ||
|
||
var $compile, | ||
scope, | ||
directiveUsage = '<ma-boolean-column field="field" value="value"></ma-boolean-column>'; | ||
|
||
beforeEach(angular.mock.module('testapp_BooleanColumn')); | ||
|
||
beforeEach(inject(function (_$compile_, _$rootScope_) { | ||
$compile = _$compile_; | ||
scope = _$rootScope_; | ||
})); | ||
|
||
it("should contain a span tag", function () { | ||
scope.field = new BooleanField(); | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].nodeName).toBe('SPAN'); | ||
}); | ||
|
||
it("should contain a span tag with classes glyphicon and glyphicon-ok when value is true", function () { | ||
scope.field = new BooleanField(); | ||
scope.value = true; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].className).toBe('glyphicon glyphicon-ok'); | ||
}); | ||
|
||
it("should contain a span tag with classes glyphicon and glyphicon-remove when value is false", function () { | ||
scope.field = new BooleanField(); | ||
scope.value = false; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].className).toBe('glyphicon glyphicon-remove'); | ||
}); | ||
|
||
it("should contain a span tag with classes glyphicon and glyphicon-ok when value is truthy", function () { | ||
scope.field = new BooleanField(); | ||
scope.value = 1; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].className).toBe('glyphicon glyphicon-ok'); | ||
}); | ||
|
||
it("should contain a span tag with classes glyphicon and glyphicon-remove when value is falsy", function () { | ||
scope.field = new BooleanField(); | ||
scope.value = 0; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].className).toBe('glyphicon glyphicon-remove'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*global angular,inject,describe,it,expect,beforeEach*/ | ||
describe('directive: checkbox-field', function () { | ||
'use strict'; | ||
|
||
var directive = require('../../../../ng-admin/Crud/field/maCheckboxField'); | ||
var Field = require('admin-config/lib/Field/Field'); | ||
angular.module('testapp_CheckboxField', []).directive('maCheckboxField', directive); | ||
|
||
var $compile, | ||
scope, | ||
directiveUsage = '<ma-checkbox-field field="field" value="value"></ma-checkbox-field>'; | ||
|
||
beforeEach(angular.mock.module('testapp_CheckboxField')); | ||
|
||
beforeEach(inject(function (_$compile_, _$rootScope_) { | ||
$compile = _$compile_; | ||
scope = _$rootScope_; | ||
})); | ||
|
||
it("should contain an input tag", function () { | ||
scope.field = new Field(); | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].nodeName).toBe('INPUT'); | ||
}); | ||
|
||
it("should use the checkbox type", function () { | ||
scope.field = new Field(); | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].type).toBe('checkbox'); | ||
}); | ||
|
||
it("should be checked according to the bounded value", function () { | ||
scope.field = new Field(); | ||
scope.value = true; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.find('input').attr('checked')).toBeTruthy(); | ||
scope.value = false; | ||
scope.$digest(); | ||
expect(element.find('input').attr('checked')).toBeFalsy(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var assert = require('chai').assert; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useless test imo, but you should definitely test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wanted to be sure of the validation.required checks in |
||
var BooleanFieldView = require('../../../../ng-admin/Crud/fieldView/BooleanFieldView'); | ||
|
||
describe('BooleanFieldView', function() { | ||
describe('getReadWidget', function() { | ||
it('should return boolean column directive', function() { | ||
var widget = BooleanFieldView.getReadWidget(); | ||
assert.include(widget, '<ma-boolean-column'); | ||
}); | ||
}); | ||
|
||
describe('getLinkWidget', function() { | ||
it('should return boolean column directive', function() { | ||
var widget = BooleanFieldView.getLinkWidget(); | ||
assert.include(widget, '<ma-boolean-column'); | ||
}); | ||
}); | ||
|
||
describe('getFilterWidget', function() { | ||
it('should return choice field directive with true and false choices', function() { | ||
var widget = BooleanFieldView.getFilterWidget(); | ||
assert.match(widget, /<ma-choice-field .* choices="\[{value: \'true\', label: \'true\' }, { value: \'false\', label: \'false\' }]"/); | ||
}); | ||
}); | ||
|
||
describe('getWriteWidget', function() { | ||
it('should return choice field directive with check for non required field', function() { | ||
var widget = BooleanFieldView.getWriteWidget(); | ||
assert.match(widget, /<ma-choice-field .* ng-if="!field\.validation\(\)\.required" .*><\/ma-choice-field>/); | ||
}); | ||
|
||
it('should return checkbox field directive with check for required field', function() { | ||
var widget = BooleanFieldView.getWriteWidget(); | ||
assert.match(widget, /<ma-checkbox-field .* ng-if="!!field\.validation\(\)\.required" .*><\/ma-checkbox-field>/); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to test both cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. We have to find another boolean field to add. Any idea ?