Skip to content

Commit 9b819ae

Browse files
committed
Support for "notitle" form option
1 parent e54615a commit 9b819ae

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

src/directives/decorators/bootstrap/bootstrap-decorator.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ function($parse, $compile, $http, $templateCache){
5353
});
5454
once();
5555
});
56-
}
5756

57+
//Keep error prone logic from the template
58+
scope.showTitle = function() {
59+
return scope.form && scope.form.notitle !== true && scope.form.title;
60+
};
61+
}
5862
};
5963
}]);
6064

src/directives/decorators/bootstrap/checkbox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="checkbox" ng-class="{'has-error': hasError()}">
2-
<label ng-show="form.title">
2+
<label ng-show="showTitle()">
33
<input type="checkbox" ng-model="$$value$$" schema-validate="form.schema" ng-required="form.required">
44
{{form.title}}
55
</label>

src/directives/decorators/bootstrap/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="form-group" ng-class="{'has-error': hasError()}">
2-
<label ng-show="form.title">{{form.title}}</label>
2+
<label ng-show="showTitle()">{{form.title}}</label>
33

44
<input type="{{form.type}}"
55
placeholder="{{form.placeholder}}"

src/directives/decorators/bootstrap/readonly.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="form-group">
2-
<label ng-show="form.title">{{form.title}}</label>
2+
<label ng-show="showTitle()">{{form.title}}</label>
33
<input ng-if="form.type !== 'textarea'" type="text" disabled class="form-control" value="{{$$value$$}}">
44
<textarea ng-if="form.type === 'textarea'" disabled class="form-control">{{$$value$$}}</textarea>
55
<span class="help-block" ng-show="form.description">{{form.description}} </span>

src/directives/decorators/bootstrap/select.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="form-group" ng-class="{'has-error': hasError()}">
2-
<label ng-show="form.title">
2+
<label ng-show="showTitle()">
33
{{form.title}}
44
</label>
55
<select ng-model="$$value$$"

src/directives/decorators/bootstrap/textarea.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="form-group" ng-class="{'has-error': hasError()}">
2-
<label ng-show="form.title">{{form.title}}</label>
2+
<label ng-show="showTitle()">{{form.title}}</label>
33
<textarea class="form-control"
44
ng-required="form.required"
55
ng-model="$$value$$"

test/schema-form-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,32 @@ describe('Schema form',function(){
441441
});
442442
});
443443

444+
it('should skip title if form says "notitle"',function(){
445+
446+
inject(function($compile,$rootScope){
447+
var scope = $rootScope.$new();
448+
scope.person = {};
449+
450+
scope.schema = exampleSchema;
451+
452+
scope.form = [{
453+
key: 'name',
454+
notitle: true
455+
},{
456+
key: 'gender',
457+
notitle: true
458+
}];
459+
460+
var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="person"></form>');
461+
462+
$compile(tmpl)(scope);
463+
$rootScope.$apply();
464+
465+
tmpl.children().length.should.be.equal(2);
466+
tmpl.children().eq(0).find('label').hasClass('ng-hide').should.be.true;
467+
tmpl.children().eq(1).find('label').hasClass('ng-hide').should.be.true;
468+
});
469+
});
444470

445471

446472
});

0 commit comments

Comments
 (0)