Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.
Closed
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
3 changes: 2 additions & 1 deletion demo/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ app.config(function($stateProvider, $urlRouterProvider, $locationProvider, forml
// or
formlyConfigProvider.setTemplateUrl({
radio: 'views/custom-field-radio.html',
checkbox: 'views/custom-field-checkbox.html'
checkbox: 'views/custom-field-checkbox.html',
buttongroup: 'views/custom-field-buttongroup.html'
});
}

Expand Down
2 changes: 1 addition & 1 deletion demo/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
.footer {
text-align: center;
padding: 25px;
}
}
19 changes: 19 additions & 0 deletions demo/views/custom-field-buttongroup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="btn-group" data-toggle="{{options.selectType==='multiple' ? 'buttons-checkbox' : 'buttons-radio'}}"
ng-required="options.required">
Custom field of type "buttongroup"
<label class="control-label">
{{options.label}}
{{options.required ? '*' : ''}}
</label>
<br>
<button type="button"
class="btn btn-primary {{$parent.result[$parent.options.key].indexOf((options.valueDelimiter || '|') + option.value + (options.valueDelimiter || '|') ) > -1 ? 'active' : ''}}"
name="{{id}}"
id="{{id + '_'+ $index}}"
ng-value="option.value"
ng-model="$parent.result[$parent.options.key || $parent.index]"
ng-click="$parent.result[$parent.options.key] = options.selectType==='single' ? (options.valueDelimiter || '|') + option.value + (options.valueDelimiter || '|') : ($parent.result[$parent.options.key].indexOf(option.value) > -1 ? $parent.result[$parent.options.key].replace((options.valueDelimiter || '|') + option.value + (options.valueDelimiter || '|'), '') : $parent.result[$parent.options.key] + (options.valueDelimiter || '|') + option.value + (options.valueDelimiter || '|'))"
ng-repeat="(key, option) in options.options">
{{option.name}}
</button>
</div>
66 changes: 64 additions & 2 deletions demo/views/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ app.controller('home', function($scope, $parse, $window, usingCustomTypeTemplate
$scope.formFieldsError = true;
}
});
$scope.$watch('formDataStr', function onDataUpdated(newValue) {
$scope.$watch('formDataStr', function onDataUpdated(newValue) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is still using spaces. This line should not change.

try {
$scope.formData = $parse(newValue)({});
$scope.formDataError = false;
Expand All @@ -59,6 +59,16 @@ app.controller('home', function($scope, $parse, $window, usingCustomTypeTemplate
}
});

$scope.$watch('editJSON', function onDataObjectUpdated(newValue) {
try {
if(newValue == true) {
$scope.formDataStr = $scope.toPrettyJSON($scope.formData, 4);
}
} catch (e) {
$scope.formDataError = true;
}
});

// Public Vars
if (usingCustomTypeTemplates) {
$scope.typeTemplatesButton = 'Use Built-in Type Templates';
Expand Down Expand Up @@ -110,7 +120,59 @@ app.controller('home', function($scope, $parse, $window, usingCustomTypeTemplate
value: 'no'
}
]
}, {
}, {
"key": "multiSelectButtons",
"type": "buttongroup",
"selectType": "multiple",
"valueDelimiter": "|",
"label": "Is this thing on?",
"options": [
{
"name": "Sure",
"value": "sure"
},
{
"name": "Nope",
"value": "nope"
},
{
"name": "Why Not?",
"value": "whynot"
}
]
}, {
"key": "singleToggle",
"type": "buttongroup",
"selectType": "multiple",
"valueDelimiter": "|",
"label": "Toggle me!",
"options": [
{
"name": "toggle",
"value": "active"
}
]
}, {
"key": "singleSelectButtons",
"type": "buttongroup",
"selectType": "single",
"required": true,
"label": "Which one is best?",
"options": [
{
"name": "Apple",
"value": "apple"
},
{
"name": "Banana",
"value": "banana"
},
{
"name": "Peach",
"value": "peach"
}
]
}, {
key: 'angularFan',
type: 'text',
label: 'Angular Fan?',
Expand Down