diff --git a/assets/js/admin/settings/conditionals.js b/assets/js/admin/settings/conditionals.js
index 20a6aa4..2a65011 100644
--- a/assets/js/admin/settings/conditionals.js
+++ b/assets/js/admin/settings/conditionals.js
@@ -120,6 +120,8 @@ function sm_hide_show_elements( target_value, current_value, not, table_row ) {
// If we should get options via Ajax.
if ( is_ajax ) {
+ sm_reset_option_value( element, ! table_row.hasClass( 'hidden' ) );
+
let data = {
'action': 'sm_settings_get_select_data',
'id': current_value,
@@ -134,19 +136,7 @@ function sm_hide_show_elements( target_value, current_value, not, table_row ) {
}
).always(
function () {
- // Reset element value.
- switch ( element.prop( 'tagName' ) ) {
- case 'SELECT':
- element.find( 'option' ).each(
- function () {
- jQuery( this.remove() );
- }
- );
- if ( ! table_row.hasClass( 'hidden' ) ) {
- element.append( jQuery( '' ).val( '' ).text( 'Loading...' ) );
- }
- break;
- }
+ sm_reset_option_value( element, ! table_row.hasClass( 'hidden' ) );
}
).done(
function ( response ) {
@@ -199,6 +189,25 @@ function sm_hide_show_elements( target_value, current_value, not, table_row ) {
}
}
+/**
+ * Clears the current option value.
+ *
+ * @type {object} The option element.
+ * @type {boolean} If we should show that it's loading.
+ */
+function sm_reset_option_value( element, write_loading ) {
+ switch ( element.prop( 'tagName' ) ) {
+ case 'SELECT':
+ element.find( 'option' ).each(
+ function () {
+ jQuery( this.remove() );
+ }
+ );
+ }
+ if ( write_loading ) {
+ element.append( jQuery( '' ).val( '' ).text( 'Loading...' ) );
+ }
+}
/**
* Checks to see if a value is set.
diff --git a/assets/js/admin/settings/conditionals.min.js b/assets/js/admin/settings/conditionals.min.js
index d67f82d..8d2f9f4 100644
--- a/assets/js/admin/settings/conditionals.min.js
+++ b/assets/js/admin/settings/conditionals.min.js
@@ -1 +1 @@
-"undefined"!=typeof sm_conditionals&&jQuery(function(){jQuery.each(sm_conditionals,function(a,b){let c=jQuery("#"+a),d=c.closest("tr");jQuery.each(b,function(a,b){let c=b.id,e=jQuery("#"+c),f=sm_isset(b.value)?b.value:b["!value"],g=sm_isset(b["!value"]);e.on("change",function(){let a=this.value;sm_hide_show_elements(f,a,g,d)}),sm_hide_show_elements(f,e.val(),g,d)})})});function sm_hide_show_elements(a,b,c,d){let e=d.find("select"),f=a!==b,g=!!e.data("ajax")&&e.data("ajax");if(f=c?!f:f,g||(f?d.addClass("hidden"):d.removeClass("hidden")),g){jQuery.ajax({method:"POST",url:ajaxurl,data:{action:"sm_settings_get_select_data",id:b}}).always(function(){switch(e.prop("tagName")){case"SELECT":e.find("option").each(function(){jQuery(this.remove())}),d.hasClass("hidden")||e.append(jQuery("").val("").text("Loading..."));}}).done(function(a){if("false"===a)a=!1;else try{a=JSON.parse(a)}catch(b){a=!1}if("object"==typeof a)switch(d.removeClass("hidden"),e.prop("tagName")){case"SELECT":e.find("option").each(function(){jQuery(this.remove())}),jQuery.each(a,function(a,b){d.find("select").append(jQuery("").val(a).text(b))});}!1===a&&d.addClass("hidden")}).fail(function(){switch(e.prop("tabName")){case"SELECT":e.append(jQuery("").val("").text("Error."));}})}}function sm_isset(a){try{return"undefined"!=typeof a}catch(a){return!1}}
\ No newline at end of file
+"undefined"!=typeof sm_conditionals&&jQuery(function(){jQuery.each(sm_conditionals,function(a,b){let c=jQuery("#"+a),d=c.closest("tr");jQuery.each(b,function(a,b){let c=b.id,e=jQuery("#"+c),f=sm_isset(b.value)?b.value:b["!value"],g=sm_isset(b["!value"]);e.on("change",function(){let a=this.value;sm_hide_show_elements(f,a,g,d)}),sm_hide_show_elements(f,e.val(),g,d)})})});function sm_hide_show_elements(a,b,c,d){let e=d.find("select"),f=a!==b,g=!!e.data("ajax")&&e.data("ajax");if(f=c?!f:f,g||(f?d.addClass("hidden"):d.removeClass("hidden")),g){sm_reset_option_value(e,!d.hasClass("hidden"));jQuery.ajax({method:"POST",url:ajaxurl,data:{action:"sm_settings_get_select_data",id:b}}).always(function(){sm_reset_option_value(e,!d.hasClass("hidden"))}).done(function(a){if("false"===a)a=!1;else try{a=JSON.parse(a)}catch(b){a=!1}if("object"==typeof a)switch(d.removeClass("hidden"),e.prop("tagName")){case"SELECT":e.find("option").each(function(){jQuery(this.remove())}),jQuery.each(a,function(a,b){d.find("select").append(jQuery("").val(a).text(b))});}!1===a&&d.addClass("hidden")}).fail(function(){switch(e.prop("tabName")){case"SELECT":e.append(jQuery("").val("").text("Error."));}})}}function sm_reset_option_value(a,b){switch(a.prop("tagName")){case"SELECT":a.find("option").each(function(){jQuery(this.remove())});}b&&a.append(jQuery("").val("").text("Loading..."))}function sm_isset(a){try{return"undefined"!=typeof a}catch(a){return!1}}
\ No newline at end of file