Fix saving/display of boolean custom fields

Boolean custom fields were no longer saved since the field was marked as
required and thus invalid when unchecked.

Even when booleans were unchecked, they were output as 'Yes' since the
text was evaluated to become the placeholder `-` before the format
helper was called, thus resulting in a truthey value.

Also, unchecked booleans are marked as placeholders since they are
falsey when empty.
pull/4452/head
Oliver Günther 9 years ago
parent fb52eb6c7f
commit 2f1d84c7cf
  1. 27
      frontend/app/components/work-packages/wp-display-attr/wp-display-attr.directive.test.ts
  2. 11
      frontend/app/components/work-packages/wp-display-attr/wp-display-attr.directive.ts
  3. 2
      frontend/app/components/wp-edit/field-types/wp-edit-boolean-field.directive.html

@ -54,7 +54,9 @@ describe('wpDisplayAttr directive', () => {
`;
I18n = _I18n_;
sinon.stub(I18n, 't').returns('');
var stub = sinon.stub(I18n, 't');
stub.withArgs('js.general_text_no').returns('No');
stub.withArgs(sinon.match.any).returns('');
element = angular.element(html);
rootScope = $rootScope;
@ -76,6 +78,7 @@ describe('wpDisplayAttr directive', () => {
beforeEach(angular.mock.inject(($q) => {
scope.workPackage = {
subject: 'Subject1',
mybool: false,
type: {id: 1, name: 'Bug'},
sheep: 10,
customField1: 'asdf1234',
@ -100,6 +103,12 @@ describe('wpDisplayAttr directive', () => {
"minLength": 1,
"maxLength": 255
},
"mybool": {
"type": "Boolean",
"name": "My Bool",
"required": false,
"writable": true
},
"sheep": {
"type": "Integer",
"name": "Sheep",
@ -111,7 +120,7 @@ describe('wpDisplayAttr directive', () => {
"name": "foobar",
"required": false,
"writable": true
}
},
"emptyField": {
"type": "String",
"name": "empty field",
@ -216,6 +225,20 @@ describe('wpDisplayAttr directive', () => {
});
});
describe('rendering a boolean field', () => {
beforeEach(() => {
scope.attribute = 'mybool';
compile();
});
it('should render the field as No', () => {
expect(element.find('.inplace-edit--read-value--value.-placeholder').length).to.eql(0);
var content = getInnermostSpan(element);
expect(content.text().trim()).to.equal('No');
});
});
describe('rendering an empty field', () => {
beforeEach(() => {
scope.attribute = 'emptyField';

@ -77,7 +77,8 @@ export class WorkPackageDisplayAttributeController {
}
public get isEmpty(): boolean {
return !this.getValue();
var value = this.getValue();
return !(value === false || value)
}
public get isDisplayAsHtml(): boolean {
@ -111,16 +112,15 @@ export class WorkPackageDisplayAttributeController {
this.setDisplayType();
var text = this.getValue() || this.placeholder;
this.displayText = this.WorkPackagesHelper.formatValue(text, this.displayType);
var text = this.WorkPackagesHelper.formatValue(this.getValue(), this.displayType);
this.displayText = text || this.placeholder;
});
}
protected getValue() {
const wpAttr:any = this.workPackage[this.attribute];
if (!wpAttr) {
if (wpAttr == null) {
return null;
}
@ -129,7 +129,6 @@ export class WorkPackageDisplayAttributeController {
if (wpAttr.hasOwnProperty('html')) {
value = wpAttr.html;
}
return value;
}
}

@ -2,8 +2,8 @@
class="wp-inline-edit--field"
wp-edit-field-requirements="vm.field.schema"
ng-model="vm.workPackage[vm.fieldName]"
ng-false-value="false"
ng-change="vm.submit()"
ng-required="vm.field.required"
ng-blur="vm.handleUserBlur()"
focus="vm.shouldFocus()"
focus-priority="vm.shouldFocus()"

Loading…
Cancel
Save