diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs index 8ae4393a8f..9d9edd0c53 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs @@ -36,9 +36,11 @@
-
+
+ data-errormsg="{{groupNameRegExViolationErrorMsg}}" class="form-control"> + +
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js index b2a5598c0f..a4fcc5ab25 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js @@ -35,12 +35,10 @@ $(function () { var description = $("input#description").val(); if (!name) { - $('.wr-validation-summary strong').text("Group Name is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); + triggerError($("input#name"),"Group Name is a required field. It cannot be empty."); return false; } else if (!inputIsValid($("input#name").data("regex"), name)) { - $('.wr-validation-summary strong').text($("input#name").data("errormsg")); - $('.wr-validation-summary').removeClass("hidden"); + triggerError($("input#name"),$("input#name").data("errormsg")); return false; } else { var group = {"name": name, "description": description}; @@ -69,6 +67,61 @@ $(function () { }); }); +/** + * @param el + * @param errorMsg + * + * Triggers validation error for provided element. + * Note : the basic jQuery validation elements should be present in the markup + * + */ +function triggerError(el,errorMsg){ + var parent = el.parents('.form-group'), + errorSpan = parent.find('span'), + errorMsgContainer = parent.find('label'); + + errorSpan.on('click',function(event){ + event.stopPropagation(); + removeErrorStyling($(this)); + el.unbind('.errorspace'); + }); + + el.bind('focusin.errorspace',function(){ + removeErrorStyling($(this)) + }).bind('focusout.errorspace',function(){ + addErrorStyling($(this)); + }).bind('keypress.errorspace',function(){ + $(this).unbind('.errorspace'); + removeErrorStyling($(this)); + }); + + errorMsgContainer.text(errorMsg); + + parent.addClass('has-error has-feedback'); + errorSpan.removeClass('hidden'); + errorMsgContainer.removeClass('hidden'); + + function removeErrorStyling(el){ + var parent = el.parents('.form-group'), + errorSpan = parent.find('span'), + errorMsgContainer = parent.find('label'); + + parent.removeClass('has-error has-feedback'); + errorSpan.addClass('hidden'); + errorMsgContainer.addClass('hidden'); + } + + function addErrorStyling(el){ + var parent = el.parents('.form-group'), + errorSpan = parent.find('span'), + errorMsgContainer = parent.find('label'); + + parent.addClass('has-error has-feedback'); + errorSpan.removeClass('hidden'); + errorMsgContainer.removeClass('hidden'); + } +} + function displayErrors(message) { $('#error-msg').html(message.responseText); modalDialog.header('Unexpected error occurred!');