Front-end mandatory-validation for radiolist and checkbox list.

This commit is contained in:
Niels Lyngsø
2019-03-05 13:20:59 +01:00
parent 21405266ef
commit 31eefe1cf9
7 changed files with 12 additions and 11 deletions

View File

@@ -43,7 +43,8 @@
value: "@",
name: "@",
text: "@",
onChange: "="
required: "=",
onChange: "&"
}
};

View File

@@ -41,7 +41,8 @@
model: "=",
value: "@",
name: "@",
text: "@"
text: "@",
required: "="
}
};

View File

@@ -3,7 +3,7 @@
value="{{value}}"
ng-model="model.checked"
class="umb-form-check__input"
ng-required="model.validation.mandatory && !model.value.length"
ng-required="required"
ng-change="onChange(model)"/>
<div class="umb-form-check__state umb-form-check__state" aria-hidden="true">

View File

@@ -2,7 +2,8 @@
<input type="radio" name="{{name}}"
value="{{value}}"
ng-model="model"
class="umb-form-check__input" />
class="umb-form-check__input"
ng-required="required" />
<div class="umb-form-check__state umb-form-check__state" aria-hidden="true">
<div class="umb-form-check__check"></div>

View File

@@ -71,15 +71,15 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro
var index = _.findIndex($scope.model.value,
function (v) {
return v === item.val;
});
}
);
if (item.checked) {
//if it doesn't exist in the model, then add it
if (index < 0) {
$scope.model.value.push(item.val);
}
}
else {
} else {
//if it exists in the model, then remove it
if (index >= 0) {
$scope.model.value.splice(index, 1);

View File

@@ -1,9 +1,7 @@
<div class="umb-property-editor umb-checkboxlist" ng-controller="Umbraco.PropertyEditors.CheckboxListController">
<ul class="unstyled">
<li ng-repeat="item in selectedItems track by item.key">
<umb-checkbox name="{{model.alias}}" value="{{item.key}}" model="item" text="{{item.val}}" on-change="changed(item)"></umb-checkbox>
<umb-checkbox name="{{model.alias}}" value="{{item.key}}" model="item" text="{{item.val}}" on-change="changed(item)" required="model.validation.mandatory && !model.value.length"></umb-checkbox>
</li>
</ul>
</div>

View File

@@ -1,7 +1,7 @@
<div class="umb-property-editor umb-radiobuttons" ng-controller="Umbraco.PropertyEditors.RadioButtonsController">
<ul class="unstyled">
<li ng-repeat="item in configItems track by item.id">
<umb-radiobutton name="{{model.alias}}" value="{{item.id}}" model="model.value" text="{{item.value}}"></umb-radiobutton>
<umb-radiobutton name="{{model.alias}}" value="{{item.id}}" model="model.value" text="{{item.value}}" required="model.validation.mandatory && model.value == ''"></umb-radiobutton>
</li>
</ul>
</div>