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

Programatically set value for Dropdown? #1302

Closed
littlehome-eugene opened this issue Feb 9, 2017 · 5 comments
Closed

Programatically set value for Dropdown? #1302

littlehome-eugene opened this issue Feb 9, 2017 · 5 comments

Comments

@littlehome-eugene
Copy link

littlehome-eugene commented Feb 9, 2017

Steps

import React from 'react'
import { Field, reduxForm } from 'redux-form'
import { Form, Dropdown, Button } from 'semantic-ui-react'


var PurchaserForm = React.createClass({

  render () {

    var { users } = this.state
    var { user } = this.props.checkout

    var userOptions = users.map((user) => {
      return {
        key: user.id,
        value: user.id,
        text: `${user.fullname} ${user.phone}`,
      }
    })
    // https://github.com/Semantic-Org/Semantic-UI-React/pull/686
    userOptions.push({
      key: '-',
      value: '-',
      text: '',
    })

    var disabled = false
    if (user.id != '-') {
      disabled = true
    }
    return (
      <Form
        >
        <Form.Field>
          <Field
            component={Dropdown}
            name="name"
            type="text"
            fluid
            search
            selection
            options={userOptions}
            onSearchChange={this.handleNameSearchChange}
            onChange={this.handleUserChange}
            value={user.id}
            disabled={disabled}
            />
        </Form.Field>
        <Button type="submit" >Submit</Button>

      </Form>
    )
  },
}

set a new user in the redux store, and PurchaserForm gets rerendered with the new

  user: {
    id: '-',
    fullname: null,
    phone: null
  }

then value={user.id} becomes value='-'

Expected Result

I expect to see "" empty text because
userOptions have

{
      key: '-',
      value: '-',
      text: '',
}

Actual Result

But it still shows the text from the previous selection

Version

0.64.3

Testcase

I think it's a bit hard to set it up

@levithomason
Copy link
Member

levithomason commented Feb 11, 2017

Programmatically setting a dropdown's value works and is fully tested. There is a working example here:

https://react.semantic-ui.com/modules/dropdown#remote

Clicking random programmatically changes the value. If you believe there is a bug please create a repro demonstrating the bug so we can investigate further.

@TallOrderDev
Copy link

I've found this link a couple times going through your issues, it seems to be broken. Might want to make them more long lasting and standardized.

@levithomason
Copy link
Member

Link fixed, thanks.

http vs https issue beyond my control at present.

@navini
Copy link

navini commented Nov 12, 2018

Can we set the options of the dropdown programatically?

@MikeGriffinReborn
Copy link

I have not found away, this is the #1 thing folks would do in programming and there is no example, we need an example that sets the options after it's created say from an HTTP Get call?

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

5 participants