Skip to content
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

form onchange is not dispatching for selected dropdown #315

Open
kvernon opened this issue Jun 18, 2024 · 3 comments
Open

form onchange is not dispatching for selected dropdown #315

kvernon opened this issue Jun 18, 2024 · 3 comments

Comments

@kvernon
Copy link

kvernon commented Jun 18, 2024

I've been test driving this package, and I'm having trouble trying to go this to dispatch the form onchange event. This package will dispatch an onchange event when using the input, but the dropdown selection does nothing to align with listening to the form's onChange event. From this, I will say this packages dropdown's onChange does show app.select direct in the console of devtools.

Compare it with the native html select / option, this will fire the dispatch, however, we all know how "fun" this node is.

The goal is to have this be included with the other form options as they trigger

import React from 'react';
import Select from 'react-dropdown-select';

export const App = function () {
    return (<form
        name="sim"
        onChange={(evt) => {
            console.log('onChange', evt);
        }}
        onSubmit={(evt) => {
            evt.preventDefault();
            console.log('submit', evt);
        }}>
        <label>
            Test Select:
            <Select
            options={[{ label: 'NONE' }, { label: 'one' }]}
            values={[]}
            labelField={'label'}
            valueField={'label'}
            onChange={function (value: { label: string }[]): void {
                console.log('app.select direct', value);
            }}
            />
        </label>
        <select>
            <option>None</option>
            <option>ONE</option>
        </select>
        <button type="submit">Save</button>
    </form>);
}
@sanusart
Copy link
Owner

Hey, try to add name property to the select. It should be playing better with forms.

Example and source: https://github.com/sanusart/react-dropdown-select/blob/master/docs/src/examples/Form.js#L14

@kvernon
Copy link
Author

kvernon commented Jun 18, 2024

Thank you for the suggestion. I just tried it, and nothing changed; meaning the form onchange still doesn't dispatch. :(

         <Select
            options={[{ label: 'NONE' }, { label: 'one' }]}
            values={[]}
            name="select"
            labelField={'label'}
            valueField={'label'}
            onChange={function (value: { label: string }[]): void {
              console.log('app.select direct', value);
            }}
          />

@sanusart
Copy link
Owner

Ah. I think I misunderstood the initial post. Select component is controlled, meaning the consumer is in charge to implement its own onChange tactics. I think best bet is using useState hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants