react-awesome-query-builder icon indicating copy to clipboard operation
react-awesome-query-builder copied to clipboard

Default value to fields in case not found

Open kundan-sde opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe. Is there any feature where we can provide default value to the field in case field value is not available in data.

Suggested JSON feature: Logic : {"var":["z", 26]} Data: {"a":1,"b":2} result : 26

Here, since z is not there in data . it takes 26 as default value.

kundan-sde avatar Aug 23 '21 05:08 kundan-sde

Have you tried defaultValue? Eg. in example in readme:

    qty: {
        defaultValue: 1,
        label: 'Qty',
        type: 'number',
        fieldSettings: {
            min: 0,
        },
        valueSources: ['value'],
        preferWidgets: ['number'],
    },

ukrbublik avatar Aug 23 '21 15:08 ukrbublik

what defaultValue does, i guess, is that it initiates the field with that value. In my usecase, I want that when jsonrule is being evaluated in backend, if the field value is not there in the db/(data is null), it does not throw error, instead , it takes up the the value as per the suggestion in top comment and evaluates the rule.

kundan-sde avatar Aug 24 '21 05:08 kundan-sde

I guess what do you want to do is to customize JsonLogic behaviour. Customize jsonLogic.apply function on backend, right?

ukrbublik avatar Aug 26 '21 14:08 ukrbublik

Yes yes

kundan-sde avatar Aug 27 '21 10:08 kundan-sde