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

How to define default value for empty array select #543

Closed
adaamz opened this issue Aug 3, 2017 · 4 comments
Closed

How to define default value for empty array select #543

adaamz opened this issue Aug 3, 2017 · 4 comments
Labels
feature New feature
Milestone

Comments

@adaamz
Copy link

adaamz commented Aug 3, 2017

Hi,
how can I define default value if the value is empty array?

$qb.queryBuilder({
    operators: [{
        type: 'approve',
        nb_inputs: 1,
        apply_to: 'select',
        multiple: true
    }],
    filters: [{
        id: 'abc',
        label: 'Abc',
        input: 'select',
        operators: ['approve'],
        default_value: 'all',
        values: {all: 'All', 5: 'a', 10: 'b', 12: 'c'}
    }]
});

And json rules:

{
    "id": "abc",
    "operator": "approve",
    "value": []
}

It does not select the value "All" :-(

Is it possible somehow?
Thanks.

@jvincilione
Copy link

Using your exact configuration, I cannot reproduce your issue. A rule without a selected value is invalid unless you explicitly allow it to be empty. (http://querybuilder.js.org/#validation)

If you set a "default_value" the default will be selected as soon as that filter is selected from the filters dropdown. In order to have no value at all selected, the user would have to explicitly deselect all values in the multi-select which would override your default.

@mistic100
Copy link
Owner

@CzechBoy talks about setRules method, not the user input.

I will plan it.

@mistic100 mistic100 added the feature New feature label Aug 4, 2017
@mistic100 mistic100 added this to the 2.4.5 milestone Aug 4, 2017
@adaamz
Copy link
Author

adaamz commented Aug 4, 2017

@mistic100 yes, I'm setting values for queryBuilder with setRules method.

Thanks.

@mistic100
Copy link
Owner

@CzechBoy will be in the next version

You will have to remove the value property or set it to undefined while calling setRules in order to use the default_value. An empty array will not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

No branches or pull requests

3 participants