From 0c188e68e8d351df1f0a79a833e0e0c460d6db76 Mon Sep 17 00:00:00 2001 From: walidmahade Date: Sun, 18 Feb 2024 19:52:43 +0600 Subject: [PATCH] optional input logic update --- dist/app.js | 16 ++++++++++++++-- src/app.js | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/dist/app.js b/dist/app.js index ffc59a1..ca33718 100644 --- a/dist/app.js +++ b/dist/app.js @@ -579,7 +579,7 @@ function hmrAccept(bundle /*: ParcelRequire */ , id /*: string */ ) { } },{}],"hXVIw":[function(require,module,exports) { -console.log("Scripts LOADER ______ LOCALHOST: 1.0"); +console.log("Scripts LOADER ______ LOCALHOST: 1.5"); const CHECKBOX_LABELS = { "subscription-important_features": "What is most important to you in a mobile subscription?", subscription_size: "Size of the subscription" @@ -655,10 +655,13 @@ const getTotalFromSizes = (prices, sizes)=>{ $(function() { let $body = $("body"); const step1OptionalFields = $("[step-1-optional-field]"); + const optionalInputs = $(".optional-field input"); // if first page, reset session storage, hide operator selection until prev question is answered if ($body.hasClass("body-calc-step1")) { // hide optional fields step1OptionalFields.hide(); + optionalInputs.removeAttr("required"); + // reset form values resetDb(); } // if last page, show offers @@ -793,7 +796,16 @@ $(function() { const $name = $input.attr("name"); saveInputValue($name, $input.val()); hideErrorMessages($el); - if ($name === HAS_ACTIVE_SUBSCRIPTION_FIELD_NAME) $(`[name=${HAS_ACTIVE_SUBSCRIPTION_FIELD_NAME}]`).prop("checked") ? step1OptionalFields.slideDown() : step1OptionalFields.slideUp(); + if ($name === HAS_ACTIVE_SUBSCRIPTION_FIELD_NAME) { + const isChecked = $(`[name=${HAS_ACTIVE_SUBSCRIPTION_FIELD_NAME}]`).prop("checked"); + if (isChecked) { + optionalInputs.attr("required", "true"); + step1OptionalFields.slideDown(); + } else { + optionalInputs.removeAttr("required"); + step1OptionalFields.slideUp(); + } + } } // radio button field on click $(".service-form").on("click", ".radio_button, .radio_button-sm", handleRadioButtonClick); diff --git a/src/app.js b/src/app.js index 0d69bd4..27600a2 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,4 @@ -console.log("Scripts LOADER ______ LOCALHOST: 1.0"); +console.log("Scripts LOADER ______ LOCALHOST: 1.5"); const CHECKBOX_LABELS = { "subscription-important_features": "What is most important to you in a mobile subscription?", @@ -79,11 +79,14 @@ const getTotalFromSizes = (prices, sizes) => { $(function () { let $body = $("body"); const step1OptionalFields = $("[step-1-optional-field]"); + const optionalInputs = $(".optional-field input"); // if first page, reset session storage, hide operator selection until prev question is answered if ($body.hasClass("body-calc-step1")) { // hide optional fields step1OptionalFields.hide(); + optionalInputs.removeAttr("required"); + // reset form values resetDb(); } @@ -247,7 +250,15 @@ $(function () { hideErrorMessages($el); if ($name === HAS_ACTIVE_SUBSCRIPTION_FIELD_NAME) { - $(`[name=${HAS_ACTIVE_SUBSCRIPTION_FIELD_NAME}]`).prop("checked") ? step1OptionalFields.slideDown() : step1OptionalFields.slideUp(); + const isChecked = $(`[name=${HAS_ACTIVE_SUBSCRIPTION_FIELD_NAME}]`).prop("checked"); + + if (isChecked) { + optionalInputs.attr("required", "true"); + step1OptionalFields.slideDown(); + } else { + optionalInputs.removeAttr("required"); + step1OptionalFields.slideUp(); + } } }