Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkboxes 'other-choice-text' field disappears when a different checkbox is selected - MVC forms #2163

Open
Superhands89 opened this issue Feb 1, 2021 · 0 comments

Comments

@Superhands89
Copy link

Using a Sitefinity MVC form with the Checkboxes control and the "other" option active, if the user selects the "other" option the other input field shows.
But if the user then also selects another option, the "other" input field disappears despite remaining checked.

image
image

I suggest maybe adding !otherCheckbox.is(':checked') to the checkboxClickHandler function in form.all.js as shown below...

var checkboxClickHandler = function (e) {
    var container = $(e.target).parents('[data-sf-role="checkboxes-field-container"]');
    var checkboxes = container.find('input[data-sf-role="checkboxes-field-input"]');
    var otherInput = $(container.find('[data-sf-checkboxes-role="other-choice-text"]').first());
    var otherCheckbox = $(container.find('[data-sf-checkboxes-role="other-choice-checkbox"]').first());
    var otherCheckboxIndex = checkboxes.index(otherCheckbox);
    var currentIndex = checkboxes.index($(e.target));
    var isRequired = container.find('[data-sf-role="required-validator"]').val() === 'True';

    if (currentIndex == otherCheckboxIndex && otherCheckbox.is(':checked')) {
        otherInput.attr('type', 'text');

        if (isRequired)
            otherInput.attr('required', 'required');
        else
            otherInput.removeAttr('required');
    }
    else if (!otherCheckbox.is(':checked')) { // Modified
        otherInput.attr('type', 'hidden');
        otherInput.removeAttr('required');
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant