Skip to content

Commit

Permalink
optional input logic update
Browse files Browse the repository at this point in the history
  • Loading branch information
walidmahade committed Feb 18, 2024
1 parent 9a79fc6 commit 0c188e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
16 changes: 14 additions & 2 deletions dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -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?",
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit 0c188e6

Please sign in to comment.