1/** 2 * Clear the custom form error. 3 */ 4const clearCustomFormError = () => { 5 getModalForm().find('.error-text').text('') 6} 7 8/** 9 * Clear the custom form message. 10 */ 11const clearCustomFormMessage = () => { 12 getModalForm().find('.message-text').text('') 13} 14 15/** 16 * Set the custom form error. 17 * 18 * @param message 19 */ 20const setCustomFormError = (message) => { 21 getModalForm().find('.error-text').html(message) 22} 23 24/** 25 * Set the custom form message. 26 * 27 * @param message 28 */ 29const setCustomFormMessage = (message) => { 30 getModalForm().find('.message-text').text(message) 31} 32 33/** 34 * Disable the submit button. 35 */ 36const disableSubmitButton = () => { 37 getSubmitButton().prop('disabled', true) 38} 39 40/** 41 * Enable the submit button. 42 */ 43const enableSubmitButton = () => { 44 getSubmitButton().prop('disabled', false) 45} 46 47/** 48 * Enable the submit button loading. 49 */ 50const enableSubmitButtonLoading = () => { 51 disableSubmitButton() 52 toggleSubmitButtonSpinner(true) 53} 54 55/** 56 * Disable the submit button loading. 57 */ 58const disableSubmitButtonLoading = () => { 59 toggleSubmitButtonSpinner(false) 60 enableSubmitButton() 61} 62 63/** 64 * Disable the button by name. 65 * 66 * @param buttonName 67 */ 68const disableButtonByName = (buttonName) => { 69 getModal().find(`button[name='${buttonName}']`).prop('disabled', true) 70} 71 72/** 73 * Enable the button by name. 74 * 75 * @param buttonName 76 */ 77const enableButtonByName = (buttonName) => { 78 getModal().find(`button[name='${buttonName}']`).prop('disabled', false) 79} 80 81/** 82 * Validate the modal form using the Yii2 ActiveForm. 83 */ 84const validateForm = () => { 85 getModalForm().yiiActiveForm('validate') 86} 87 88const getSubmitButton = () => { 89 return getModalForm().find('button[type="submit"]') 90} 91 92/** 93 * Check if the modal form has errors. 94 * 95 * @returns {boolean} 96 */ 97const formHasErrors = () => { 98 return getModalForm().find('.has-error').length > 0 99} 100 101/** 102 * Toggle the modal form spinner if it exists. 103 * 104 * @param displayed 105 */ 106const toggleFormSpinner = (displayed) => { 107 const spinner = getModalForm().find('.form-loading-spinner') 108 109 if (spinner) { 110 displayed 111 ? spinner.removeClass('d-none') 112 : spinner.addClass('d-none') 113 } 114} 115 116/** 117 * Toggle the submit button spinner if it exists. 118 * 119 * @param displayed - boolean 120 */ 121const toggleSubmitButtonSpinner = (displayed) => { 122 toggleButtonSpinner(getSubmitButton(), displayed) 123} 124 125/** 126 * Toggle the button spinner if it exists. 127 * 128 * @param button - jQuery object 129 * @param displayed - boolean 130 */ 131const toggleButtonSpinner = (button, displayed) => { 132 const spinner = button.find('.spinner-border') 133 134 if (spinner) { 135 displayed 136 ? spinner.removeClass('d-none') 137 : spinner.addClass('d-none') 138 } 139} 140 141/** 142 * After the modal form is validated, check if it has errors. 143 * If it has errors, disable the submit button 144 * otherwise enable the submit button. 145 */ 146getModal().find('form').on('afterValidate', (e, messages, errorAttributes) => { 147 // if (errorAttributes.length) { 148 // disableSubmitButton() 149 // } else { 150 // enableSubmitButton() 151 // } 152}) 153 154/** 155 * Clear the custom form error on input change. 156 * Delegated: the registration forms are loaded into the modal later, over ajax. 157 */ 158$(document).on('change', getModalSelector('form input'), () => { 159 clearCustomFormError() 160})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.