From 080c9e8fadf9c1f00b176252f262776f276b3544 Mon Sep 17 00:00:00 2001 From: NiclasNorin <103985736+NiclasNorin@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:17:37 +0200 Subject: [PATCH] Fix: Conditions not working for form fields (#87) --- source/js/admin/conditional-admin.js | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/source/js/admin/conditional-admin.js b/source/js/admin/conditional-admin.js index ebe451fc..80b4dd7d 100644 --- a/source/js/admin/conditional-admin.js +++ b/source/js/admin/conditional-admin.js @@ -22,21 +22,23 @@ export default (function ($) { selected = $selected.val(); } else { // Get selected from database - var fieldName = $(element).attr('name'); - $.ajax({ - url: ajaxurl, - type: 'post', - data: { - action : 'get_selected_field', - moduleId : modularity_current_post_id, - fieldName : fieldName - }, - success: function(response) { - if (response != 'error') { - $("option[value='" + response + "']", element).prop('selected', true); - } - } - }); + if (typeof modularity_current_post_id !== 'undefined') { + var fieldName = $(element).attr('name'); + $.ajax({ + url: ajaxurl, + type: 'post', + data: { + action : 'get_selected_field', + moduleId : modularity_current_post_id, + fieldName : fieldName + }, + success: function(response) { + if (response != 'error') { + $("option[value='" + response + "']", element).prop('selected', true); + } + } + }); + } } // Reset select options