Code Monkey home page Code Monkey logo

Comments (8)

sja-cslab avatar sja-cslab commented on June 23, 2024 1

@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.

melloware avatar melloware commented on June 23, 2024 1

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.

sja-cslab avatar sja-cslab commented on June 23, 2024

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.

Rekl0w avatar Rekl0w commented on June 23, 2024

https://stackblitz.com/edit/vitejs-vite-tmd4yk?file=src%2FApp.tsx

I changed your code a bit. This should work.

from primereact.

sja-cslab avatar sja-cslab commented on June 23, 2024

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.

Rekl0w avatar Rekl0w commented on June 23, 2024

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.

sja-cslab avatar sja-cslab commented on June 23, 2024

I would expect that if I do not set optionValue, that I get back whatever I throw in.

from primereact.

sja-cslab avatar sja-cslab commented on June 23, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.