Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass in boolean to preventEnterSubmit directive #8639

Merged
merged 11 commits into from
Mar 31, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ angular.module("umbraco.directives")
}

$(element).on("keypress", function (event) {
if (event.which === 13) {
if (event.which === 13 && enabled === true) {
event.preventDefault();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
angular.module("umbraco.directives")
.directive('umbAutoFocus', function($timeout) {

return function(scope, element, attr){
return function (scope, element, attrs) {
var update = function() {
//if it uses its default naming
if(element.val() === "" || attr.focusOnFilled){
if (element.val() === "" || attrs.focusOnFilled){
element.trigger("focus");
}
};

if (attr.umbAutoFocus !== "false") {
var enabled = true;
//check if there's a value for the attribute, if there is and it's false then we conditionally don't
//use auto focus.
if (attrs.umbAutoFocus) {
attrs.$observe("umbAutoFocus", function (newVal) {
enabled = (newVal === "false" || newVal === 0 || newVal === false) ? false : true;
});
}

if (enabled) {
$timeout(function() {
update();
});
}
};
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@
vm.change = change;

function onInit() {
vm.inputId = vm.inputId || "umb-check_" + String.CreateGuid();
vm.inputId = vm.inputId || "umb-search-filter_" + String.CreateGuid();
vm.autoFocus = vm.autoFocus === true;
vm.preventSubmitOnEnter = vm.preventSubmitOnEnter === true;

// If a labelKey is passed let's update the returned text if it's does not contain an opening square bracket [
if (vm.labelKey) {
localizationService.localize(vm.labelKey).then(function (data) {
if(data.indexOf('[') === -1){
vm.text = data;
if (data.indexOf('[') === -1){
vm.text = data;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,14 @@
<div class="form-search form-search-filter">
<label for="{{vm.inputId}}" class="sr-only">{{vm.text}}</label>
<i class="icon-search" aria-hidden="true"></i>
<input
ng-if="vm.preventSubmitOnEnter"
id="{{vm.inputId}}"
type="text"
ng-change="vm.change()"
ng-model="vm.model"
class="umb-search-field search-query search-input input-block-level"
placeholder="{{vm.text}}"
umb-auto-focus="{{vm.autoFocus === true}}"
prevent-enter-submit
no-dirty-check />

<input
ng-if="!vm.preventSubmitOnEnter"
id="{{vm.inputId}}"
type="text"
ng-change="vm.change()"
ng-model="vm.model"
class="umb-search-field search-query search-input input-block-level"
placeholder="{{vm.text}}"
umb-auto-focus="{{vm.autoFocus === true}}"
no-dirty-check />
<input type="text"
id="{{vm.inputId}}"
ng-change="vm.change()"
ng-model="vm.model"
class="umb-search-field search-query search-input input-block-level"
placeholder="{{vm.text}}"
umb-auto-focus="{{vm.autoFocus}}"
prevent-enter-submit="{{vm.preventSubmitOnEnter}}"
no-dirty-check />
</div>
</div>