1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 01:34:31 +02:00

Update inputfields.js for better error handling and improved reload support

This commit is contained in:
Ryan Cramer
2022-10-06 13:14:55 -04:00
parent 32d7a09cfd
commit 96bb90bb2e
2 changed files with 19 additions and 9 deletions

View File

@@ -2349,17 +2349,27 @@ function InputfieldReloadEvent(event, extraData) {
consoleLog('Inputfield reload: ' + fieldName); consoleLog('Inputfield reload: ' + fieldName);
$.get(url, function(data) { $.get(url, function(data) {
var id = $t.attr('id'); var id = $t.attr('id');
var $content = jQuery(data).find("#" + id).children(".InputfieldContent"); var $content;
if(!$content.length && id.indexOf('_repeater') > -1) { if(data.indexOf('{') === 0) {
id = 'wrap_Inputfield_' + fieldName; data = JSON.parse(data);
console.log(data);
$content = '';
} else {
$content = jQuery(data).find("#" + id).children(".InputfieldContent"); $content = jQuery(data).find("#" + id).children(".InputfieldContent");
if(!$content.length) { if(!$content.length && id.indexOf('_repeater') > -1) {
console.log("Unable to find #" + $t.attr('id') + " in response from " + url); id = 'wrap_Inputfield_' + fieldName;
$content = jQuery(data).find("#" + id).children(".InputfieldContent");
if(!$content.length) {
console.log("Unable to find #" + $t.attr('id') + " in response from " + url);
}
} }
} }
$t.children(".InputfieldContent").html($content.html()); if($content.length) {
// if(typeof jQuery.ui != 'undefined') $t.effect("highlight", 1000); $t.children(".InputfieldContent").html($content.html());
$t.trigger('reloaded', [ 'reload' ]); //InputfieldStates($t);
InputfieldsInit($t);
$t.trigger('reloaded', ['reload']);
}
}); });
event.stopPropagation(); event.stopPropagation();
} }

File diff suppressed because one or more lines are too long