Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ================================================
- // Validate-Form Extension (Create Guideline) module for BP, used on Admin Create Guideline page
- // ================================================
- (function () {
- 'use strict';
- bp.Modules.ValidateFormExtensionCreateGuideline = {
- init: function () {
- this.validateForm();
- },
- //block form submission
- validateForm: function() {
- var _this = this;
- $('#create-guideline').submit(function (evt) {
- if ($('#guidelineList ul li').length === 0) {
- evt.preventDefault();
- _this.toggleErrorMsg();
- }
- });
- },
- toggleErrorMsg: function() {
- $('.validate-form-extension-js').removeClass('d-none').addClass('has-danger');
- $('#q2').addClass('has-error');
- // TODO fix scroll position
- $('html, body').animate({
- scrollTop: $('#q2').offset().top
- }, 500);
- this.observeMutation();
- },
- observeMutation: function() {
- var targetNode = $('#guidelineList ul')[0]
- var config = { childList: true };
- var callback = function(mutationsList, observer) {
- for (var i = 0; i < mutationsList.length; i++) {
- var mutation = mutationsList[i];
- if (mutation.type === "childList") {
- console.log("A child node has been added or removed.");
- $('.validate-form-extension-js').addClass('d-none');
- $('#q2').removeClass('has-error');
- }
- }
- };
- var observer = new MutationObserver(callback);
- observer.observe(targetNode, config);
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment