Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ================================================
  2. // Validate-Form Extension (Create Guideline) module for BP, used on Admin Create Guideline page
  3. // ================================================
  4.  
  5. (function () {
  6.     'use strict';
  7.  
  8.     bp.Modules.ValidateFormExtensionCreateGuideline = {
  9.  
  10.         init: function () {
  11.             this.validateForm();
  12.         },
  13.  
  14.         //block form submission
  15.         validateForm: function() {
  16.             var _this = this;
  17.             $('#create-guideline').submit(function (evt) {
  18.                 if ($('#guidelineList ul li').length === 0) {
  19.                     evt.preventDefault();
  20.                     _this.toggleErrorMsg();
  21.                 }
  22.             });
  23.         },
  24.  
  25.         toggleErrorMsg: function() {
  26.             $('.validate-form-extension-js').removeClass('d-none').addClass('has-danger');
  27.             $('#q2').addClass('has-error');
  28.             // TODO fix scroll position
  29.             $('html, body').animate({
  30.                 scrollTop: $('#q2').offset().top
  31.             }, 500);
  32.             this.observeMutation();
  33.         },
  34.  
  35.         observeMutation: function() {
  36.             var targetNode = $('#guidelineList ul')[0]
  37.             var config = { childList: true };
  38.             var callback = function(mutationsList, observer) {
  39.                 for (var i = 0; i < mutationsList.length; i++) {
  40.                     var mutation = mutationsList[i];
  41.                     if (mutation.type === "childList") {
  42.                         console.log("A child node has been added or removed.");
  43.                         $('.validate-form-extension-js').addClass('d-none');
  44.                         $('#q2').removeClass('has-error');
  45.                     }
  46.                 }
  47.             };
  48.             var observer = new MutationObserver(callback);
  49.             observer.observe(targetNode, config);
  50.         }
  51.     }
  52. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement