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
Ability to get the input type on generated rules from JSON. #226
Comments
I don't want to add import { RuleGroupType, RuleType } from 'react-querybuilder';
const fields = [
{ name: 'description', label: 'Description', inputType: 'string' },
{ name: 'price', label: 'Price', inputType: 'number' }
];
const processRule = (r: RuleType): RuleType & { inputType?: string } => ({
...r,
inputType: fields.find((f) => f.name === r.field)?.inputType
});
const processGroup = (rg: RuleGroupType): RuleGroupType => ({
...rg,
rules: rg.rules.map((r: RuleType | RuleGroupType) => {
if (r['field' as 'id']) {
return processRule(r as RuleType);
}
return processGroup(r as RuleGroupType);
})
});
const result = processGroup(query); To remove the JSON.stringify(query, ['rules', 'field', 'value', 'operator', 'combinator']); That will stringify your query but only export the properties listed in the second argument array. This is exactly how the |
Hey @jakeboone02 , thanks for the fast reply and help! Works like a charm. Thanks for the help and for the amazing library, you rock. |
Aw, thanks! I really appreciate that. Glad to help. |
Hello!
Thanks for the awesome library!
I was wondering if it's somehow possible to get the "inputType" on the final generated rule object when exporting to JSON.
Also, is it possible to remove the "not" property from the object when using 'formatQuery'?
Thanks!
The text was updated successfully, but these errors were encountered: