Skip to content

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

@Superhands89

Description

@Superhands89

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');
    }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions