Open karthikCrmwebx opened 3 months ago
Do you want to add value/type switcher (as on 2nd screenshot) for "custom drop down" (on screenshot 1)?
Or completely different component, not built-in value/type switcher?
both are required for our use cases.
As for 1st case, there should be 2+ fields of type select in your config. And you should use valueSources: ["value", "field"]
, not valueSources: ["value"]
can you elaborate more or give give some sample since getting "Object literal may only specify known properties, but 'valueSources' does not exist in type 'SelectWidget<Config, SelectWidgetProps
I mean these lines in your code
valueSources: checkFieldIsOfAnyOptionSet(field.controlType)
? ["value"]
: undefined,
Please try without it
tried but still getting same
Could you please create a sandbox to reproduce your issue? You can take this as example https://github.com/ukrbublik/react-awesome-query-builder/tree/master/packages/sandbox_simple
how about adding our custom component to the query builder?
You can use renderBeforeWidget
in config.settings
any example can you share
how can we add valueSources : ["value", "field", "ourCustomComponent"] on select of ourCustomComponent, my components should render
valueSources
array can only have values: value, field, func
Please share a sandbox to demonstrate your issue and requested change
https://codesandbox.io/p/sandbox/modest-tdd-ywnc6g?file=%2Fsrc%2Fdemo%2Findex.jsx
click on add rule and select optSet values
If you want to compare [optset_values]
with other field, you should have any other field in config with type select
, eg:
You can render custom select like this:
renderBeforeWidget: (props) => {
const {
selectedField,
selectedOperator,
} = props;
if (selectedField?.includes("[optset_values]") && selectedOperator) {
return (
<select
onChange={({ target: { value } }) => {
console.log(value);
}}
>
<option value="one">one</option>
<option value="two">two</option>
</select>
);
}
},
But right now there is no way to store meta data for rule in store (as you can inspect from the props of renderBeforeWidget). I can add support of this in the future. If it suits you, could you describe your case? Like why do you need to display custom select before the value widget, how do you plan to use its value, store its value, what format? Thanks
thanks for that.
if we have render renderBeforeWidget:(props: any) => <CustomComponent {...props} /> can we stop rendering the highlighted value and enter value in the same sandbox
No. But instead of renderBeforeWidget
you can use a custom component (widget) for your field [optset_values]
https://codesandbox.io/p/sandbox/broken-flower-r9hqf9?file=%2Fsrc%2Fdemo%2Fconfig.jsx%3A109%2C20
// use widget select_custom
const fields = {
...
"[optset_values]": {
type: "select",
preferWidgets: ["select_custom"],
...
};
// add widget select_custom
const widgets = {
...
select_custom: {
type: "select",
factory: (props) => {
console.log("select_custom prtops", props);
return (
<div>
{"custom select"}
<select
value={props.value}
onChange={({ target: { value } }) => {
props.setValue(value);
}}
>
{props.listValues.map(({ value, title }) => (
<option value={value}>{title}</option>
))}
</select>
</div>
);
},
},
};
// allow operators for widget select_custom
const types = {
...
select: merge({}, InitialConfig.types.select, {
widgets: {
select_custom: {
operators: ["select_equals"],
},
},
}),
};
cannot access your sandbox can you provide access
how can we have multi-select
How can we add the value and filed drop down for the type select [in the below code for option set] ? can we add our custom component to the query builder?