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

Feature request: disable fields action handler #12

Open
Seb33300 opened this issue May 21, 2021 · 2 comments
Open

Feature request: disable fields action handler #12

Seb33300 opened this issue May 21, 2021 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Seb33300
Copy link

Seb33300 commented May 21, 2021

Hello,

I would like to see a new action handler disableFields very similar to the clearFields handler.

Instead of clearing fields, I would like to disable them.

It's quite similar to the clearFields because disabled field are not submitted.
But the advantage is that if the user hide the field, and then display it again, all the values he started to enter are not lost.
Its also possible to set default values that will not be cleared and not submitted if the fields are hidden.

Thank you

@rguliev
Copy link
Owner

rguliev commented May 21, 2021

Hello,

Thanks for your suggestion. I am not sure if I got your idea. It would be nice if you could provide a PR or, at least, an example.

Another thing is that for disableFields it is not enough to have one action, so one will need also to un-disable fields. So, it looks like it is simpler to write your custom ifTrue and ifFalse functions.

@rguliev rguliev closed this as completed Nov 19, 2022
@Seb33300
Copy link
Author

Oups, sorry I never answered this.
Here is how I fixed it:

$('...').conditionize({
    ifTrue: [
        // ...
        function ($s) {
            if ($s.is('option')) {
                $s.prop('disabled', false).insertAfter($s.parent().find(':not([disabled]):last'));
            } else {
                $s.find('input, select, textarea, button').prop('disabled', false);
            }
        }
    ],
    ifFalse: [
        // ...
        function ($s) {
            if ($s.is('option')) {
                if ($s.is(':selected')) {
                    $s.closest('select').val(null);
                }
                $s.prop('disabled', true).appendTo($s.parent());
            } else {
                $s.find('input, select, textarea, button').prop('disabled', true);
            }
        }
    ]
});

@rguliev rguliev added enhancement New feature or request help wanted Extra attention is needed labels Nov 21, 2022
@rguliev rguliev reopened this Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants