react-redux-form icon indicating copy to clipboard operation
react-redux-form copied to clipboard

Select defaultValue do not change the modelValue

Open ramiel opened this issue 7 years ago • 7 comments

Setting defaultValue on a Control.select do not set it to the modelValue. After changing the option on the select the value is correctly propagated

ramiel avatar Oct 21 '16 12:10 ramiel

@ramiel I cannot reproduce this issue (at least if I understand correctly).

        <Control.select defaultValue="foo" model="user.choice">
          <option value="">Please choose an option</option>
          <option value="foo">Foo!</option>
          <option value="bar">Bar!</option>
        </Control.select>

The above code will set both the control's view value to "foo" and the model in the Redux store to user.choice = "foo". Is that what you are expecting?

davidkpiano avatar Oct 22 '16 15:10 davidkpiano

Closing this due to inactivity.

davidkpiano avatar Oct 28 '16 14:10 davidkpiano

+1 — Does not work for me either on localForm

iBasit avatar Jan 16 '18 17:01 iBasit

@iBasit Can you create a reproducible example?

davidkpiano avatar Jan 16 '18 19:01 davidkpiano

I can share my code with you, which is following:

{row.status === 'open' ? <td style={{width: 70}}><LocalForm className="form-group">
            <Control.select defaultValue={row.orderType} model=".orderType" updateOn="change" changeAction={(model, value) => (value !== row.orderType) ? update(row._id, {orderType: value}) : ''} className="form-control form-control-sm">
            <option value="">Default Limit + Thrust + Inr</option>
            <option value="TAKE_PROFIT_LIMIT">TPS Take Profit STOP (Thrust + Inr)</option>
            <option value="STOP_LOSS_LIMIT">TLS Take Loss STOP (Thrust + Inr)</option>
            <option value="TAKE_PROFIT">TP Take Profit on Limit (Thrust ignored)</option>
            <option value="STOP_LOSS">TL Take Loss on Limit (Thrust ignored)</option>
            <option value="LIMIT">Limit (exact price) (Thrust ignored)</option>
        </Control.select></LocalForm></td> : <td></td>}

before this code, I have other sibling localForms, which I just use the value with placeholder, since defaultValue was not working, but for drop down I can't do that.

other siblings

{row.status === 'open' ? <td style={{width: 70}}><LocalForm className="form-group"><Control.text model=".limit" updateOn="blur" changeAction={(model, value) => (value && value !== row.limit) ? update(row._id, {limit: parseFloat(value)}) : ''} placeholder={row.limit} className="form-control form-control-sm" /></LocalForm></td> : <td></td>}
        {row.status === 'open' ? <td style={{width: 70}}><LocalForm className="form-group"><Control.text model=".thrust" updateOn="blur" changeAction={(model, value) => (value && value !== row.thrust) ? update(row._id, {thrust: parseFloat(value)}) : ''} placeholder={row.thrust} className="form-control form-control-sm" /></LocalForm></td> : <td></td>}
        {row.status === 'open' ? <td style={{width: 70}}><LocalForm className="form-group"><Control.text model=".incrementBy" updateOn="blur" changeAction={(model, value) => (value && value !== row.incrementBy) ? update(row._id, {incrementBy: parseFloat(value)}) : ''} placeholder={row.incrementBy} className="form-control form-control-sm" /></LocalForm></td> : <td></td>}
        
"dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "react-redux-form": "^1.16.3",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-router-redux": "next",
    "redux": "^3.7.2",
    "redux-socket.io": "^1.4.0",
    "redux-thunk": "^2.2.0",
    "sanitize.css": "^5.0.0",
    "socket.io-client": "^2.0.4",
  },

btw I'm creating many forms, just to update each row value, since I can't put localForm on <tr> tag.

iBasit avatar Jan 16 '18 19:01 iBasit

do you know when can we expect a fix for this? This is very important for our project or any project.

iBasit avatar Jan 18 '18 03:01 iBasit

If you know the probable fix, feel free to open a PR. I can't guarantee when I will be able to have the time to investigate or fix this, but I can guarantee that all good PRs will be merged and released promptly.

davidkpiano avatar Jan 18 '18 03:01 davidkpiano