Skip to content
Open
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
21 changes: 20 additions & 1 deletion src/directives/decorators/bootstrap/select.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="form-group {{form.htmlClass}} schema-form-select"
<div ng-if="form.allowAutoNullOption !== undefined" class="form-group {{form.htmlClass}} schema-form-select"
ng-class="{'has-error': hasError(), 'has-success': hasSuccess(), 'has-feedback': form.feedback !== false}">
<label class="control-label" ng-show="showTitle()">
{{form.title}}
Expand All @@ -11,6 +11,25 @@
schema-validate="form"
ng-options="item.value as item.name group by item.group for item in form.titleMap"
name="{{form.key.slice(-1)[0]}}">
<option ng-if="form.allowAutoNullOption !== false" value="">{{form.allowAutoNullOption !== true ? form.allowAutoNullOption : ''}}</option>
</select>
<div class="help-block" sf-message="form.description"></div>
</div>
<div ng-if="form.allowAutoNullOption === undefined" class="form-group {{form.htmlClass}} schema-form-select"
ng-class="{'has-error': hasError(), 'has-success': hasSuccess(), 'has-feedback': form.feedback !== false}">
<label class="control-label" ng-show="showTitle()">
{{form.title}}
</label>
<select ng-model="$$value$$"
ng-model-options="form.ngModelOptions"
ng-disabled="form.readonly"
sf-changed="form"
class="form-control {{form.fieldHtmlClass}}"
schema-validate="form"
ng-options="item.value as item.name for item in form.titleMap"
name="{{form.key.slice(-1)[0]}}">
</select>
<div class="help-block"
ng-show="(hasError() && errorMessage(schemaError())) || form.description"
ng-bind-html="(hasError() && errorMessage(schemaError())) || form.description"></div>
</div>
13 changes: 13 additions & 0 deletions src/services/schema-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,19 @@ angular.module('schemaForm').provider('schemaForm',
}
}

if (obj.type === 'select' && obj.titleMap) {
// we check whether null value is in titleMap. if so, we fix possible null
// label and set allowAutoNullOption to false, then leave the titleMap as it is
obj.titleMap.forEach(function(item) {
if (item.value === null) {
if (obj.allowAutoNullOption === undefined)
obj.allowAutoNullOption = false;
if (item.name === null)
item.name = '';
}
});
}

// Are we inheriting readonly?
if (readonly === true) { // Inheriting false is not cool.
obj.readonly = true;
Expand Down