Comments (8)
@Rekl0w, I see your point; however, it feels wrong that the component works differently based on how something looks inside.
If I pass, for example, [{foo: "label", bar: "value"}, {foo: "label2", bar: "value2"}]
and use optionLabel="foo"
, I'll get the whole object in onChange
. If I rename those bar
properties to value
, it won't work anymore. I hope you get my point.
@melloware Could we make that to a feature/enhancement request? What about an extra option "workWithObject" or something? :)
from primereact.
Yes this has always been a weird contention with using Object vs Primitive and letting it know which JSON fields you mean to use for value and label.
from primereact.
I noticed that this is not an error. My problem here is noted in the docs:
If optionValue is omitted and the object has no value property, the object itself becomes the value of an option
So this is more a question than a Bug => How can I get and set the Object, even if it has a value
property?
from primereact.
https://stackblitz.com/edit/vitejs-vite-tmd4yk?file=src%2FApp.tsx
I changed your code a bit. This should work.
from primereact.
That works, and I'm using it in other parts of my code. However, now if I need to work with that object, for example, in the onChange event, I need to find it within the options. So, that is an acceptable workaround but not a real solution for that problem.
I guess you want to say, 'you cannot get an object directly from the component if it has a value property,' correct?
from primereact.
value
prop is need to work with a state that can be changed but if you give a static value to it, it won't change.
I guess you want to say, 'you cannot get an object directly from the component if it has a value property,' correct?
You can get an object with onChange
method but this component is not sets the object directly. It sets the value
prop and works with it.
from primereact.
I would expect that if I do not set optionValue, that I get back whatever I throw in.
from primereact.
@melloware just looked at the code
const getOptionValue = (option) => {
return props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : ObjectUtils.resolveFieldData(option, 'value') || option;
};
The question I have here is why it has been decided that it is a good idea to try to resolve option.value
if no optionValue
is set. Why not just return option then? Without digging deeper, I would expect option to be a primitive if only primitives are available.
from primereact.
Related Issues (20)
- DataTable: Reordering Columns Causes Duplication in Checkbox Column and Reorder Row Indicator Column HOT 1
- Dropdown: No longer shows options with simple primitive values HOT 1
- InputOtp: Setting Value does not clear display
- Password > Icon and Input render order > tabIndex issue HOT 1
- Typo error on the Theming page HOT 1
- DataTable: re-order + resizable fails HOT 2
- Typo error on `PrimeFlex` section of the Theming documentation HOT 1
- Readme typo HOT 1
- Sidebar: Headless Sidebar is hidden in Small and Medium-Sized Views HOT 1
- PanelMenu MenuItem Id Prop Not Passed
- DataTable: Row groups are duplicated when the groupRowsBy value is changed
- onSort return only one value on every event HOT 2
- MeterGroup: Percentages always based on max 100 HOT 3
- DataTable Dropdown Filter: Value is not getting updated upon selection HOT 4
- Chart property "onMouseDown" not typed HOT 1
- TabView | Inkbar is visible for lara
- Option with value 0 has different behavior than any other number in dropdown HOT 6
- Cannot npm link primereact on local project
- DataTable: Clicking on a checkbox in the header of a sortable column will sort the column HOT 2
- FileUpload: How can I preload a file into the component? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from primereact.