mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Add handleValidationMessage override function
This commit is contained in:
parent
88ed5c2c64
commit
6cd76e9c6d
@ -17,11 +17,13 @@ if (window.jQuery === undefined)
|
||||
/*
|
||||
* Validate handler name
|
||||
*/
|
||||
if (handler == undefined)
|
||||
if (handler == undefined) {
|
||||
throw new Error('The request handler name is not specified.')
|
||||
}
|
||||
|
||||
if (!handler.match(/^(?:\w+\:{2})?on*/))
|
||||
if (!handler.match(/^(?:\w+\:{2})?on*/)) {
|
||||
throw new Error('Invalid handler name. The correct handler name format is: "onEvent".')
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare the options and execute the request
|
||||
@ -50,8 +52,13 @@ if (window.jQuery === undefined)
|
||||
options.data[inputName] = $el.val()
|
||||
}
|
||||
|
||||
if (options.data !== undefined && !$.isEmptyObject(options.data))
|
||||
if (options.data !== undefined && !$.isEmptyObject(options.data)) {
|
||||
data.push($.param(options.data))
|
||||
}
|
||||
|
||||
if ($.type(loading) == 'string') {
|
||||
loading = $(loading)
|
||||
}
|
||||
|
||||
var requestHeaders = {
|
||||
'X-OCTOBER-REQUEST-HANDLER': handler,
|
||||
@ -62,10 +69,6 @@ if (window.jQuery === undefined)
|
||||
requestHeaders['X-OCTOBER-REQUEST-FLASH'] = 1
|
||||
}
|
||||
|
||||
if ($.type(loading) == 'string') {
|
||||
loading = $(loading)
|
||||
}
|
||||
|
||||
var requestOptions = {
|
||||
url: window.location.href,
|
||||
context: context,
|
||||
@ -157,16 +160,6 @@ if (window.jQuery === undefined)
|
||||
options.evalComplete && eval('(function($el, context, data, textStatus, jqXHR) {'+options.evalComplete+'}.call($el.get(0), $el, context, data, textStatus, jqXHR))')
|
||||
},
|
||||
|
||||
/*
|
||||
* Custom function, display an error message to the user
|
||||
*/
|
||||
handleErrorMessage: function(message) {
|
||||
var _event = jQuery.Event('ajaxErrorMessage')
|
||||
$(window).trigger(_event, [message])
|
||||
if (_event.isDefaultPrevented()) return
|
||||
if (message) alert(message)
|
||||
},
|
||||
|
||||
/*
|
||||
* Custom function, requests confirmation from the user
|
||||
*/
|
||||
@ -186,6 +179,38 @@ if (window.jQuery === undefined)
|
||||
if (message) return confirm(message)
|
||||
},
|
||||
|
||||
/*
|
||||
* Custom function, display an error message to the user
|
||||
*/
|
||||
handleErrorMessage: function(message) {
|
||||
var _event = jQuery.Event('ajaxErrorMessage')
|
||||
$(window).trigger(_event, [message])
|
||||
if (_event.isDefaultPrevented()) return
|
||||
if (message) alert(message)
|
||||
},
|
||||
|
||||
/*
|
||||
* Custom function, focus fields with errors
|
||||
*/
|
||||
handleValidationMessage: function(message, fields) {
|
||||
$triggerEl.trigger('ajaxValidation', [context, message, fields])
|
||||
|
||||
var isFirstInvalidField = true
|
||||
$.each(fields, function focusErrorField(fieldName, fieldMessages) {
|
||||
var fieldElement = $form.find('[name="'+fieldName+'"], [name="'+fieldName+'[]"], [name$="['+fieldName+']"], [name$="['+fieldName+'][]"]').filter(':enabled').first()
|
||||
if (fieldElement.length > 0) {
|
||||
|
||||
var _event = jQuery.Event('ajaxInvalidField')
|
||||
$(window).trigger(_event, [fieldElement.get(0), fieldName, fieldMessages, isFirstInvalidField])
|
||||
|
||||
if (isFirstInvalidField) {
|
||||
if (!_event.isDefaultPrevented()) fieldElement.focus()
|
||||
isFirstInvalidField = false
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/*
|
||||
* Custom function, display a flash message to the user
|
||||
*/
|
||||
@ -249,25 +274,10 @@ if (window.jQuery === undefined)
|
||||
}
|
||||
|
||||
/*
|
||||
* Focus fields with errors
|
||||
* Handle validation
|
||||
*/
|
||||
if (data['X_OCTOBER_ERROR_FIELDS']) {
|
||||
$triggerEl.trigger('ajaxValidation', [context, data['X_OCTOBER_ERROR_MESSAGE'], data['X_OCTOBER_ERROR_FIELDS']])
|
||||
|
||||
var isFirstInvalidField = true
|
||||
$.each(data['X_OCTOBER_ERROR_FIELDS'], function focusErrorField(fieldName, fieldMessages) {
|
||||
var fieldElement = $form.find('[name="'+fieldName+'"], [name="'+fieldName+'[]"], [name$="['+fieldName+']"], [name$="['+fieldName+'][]"]').filter(':enabled').first()
|
||||
if (fieldElement.length > 0) {
|
||||
|
||||
var _event = jQuery.Event('ajaxInvalidField')
|
||||
$(window).trigger(_event, [fieldElement.get(0), fieldName, fieldMessages, isFirstInvalidField])
|
||||
|
||||
if (isFirstInvalidField) {
|
||||
if (!_event.isDefaultPrevented()) fieldElement.focus()
|
||||
isFirstInvalidField = false
|
||||
}
|
||||
}
|
||||
})
|
||||
requestOptions.handleValidationMessage(data['X_OCTOBER_ERROR_MESSAGE'], data['X_OCTOBER_ERROR_FIELDS'])
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user