dcsimg
Results 1 to 2 of 2

Thread: [RESOLVED] React - antd - DatePicker - Which one changed?

  1. #1

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,836

    Resolved [RESOLVED] React - antd - DatePicker - Which one changed?

    I have a form with multiple DatePicker components on it from ant-design. For the most part it works. The problem is that they are all tied to the same onChange event handler (for simplicity, and because they are all rendered in a loop). I'm getting the date coming through just fine (param 2 of the event handler) but what I can't seem to determine is WHICH of the 5 date pickers is the one that triggered the change. This is a problem because I have other data on the row I need to associate the date with. I've added a name attribute, but it's not passed through to the handler, grrrr, so it isn't doing me any good.
    So, does anyone know how to get the name of the (antd) datepicker that triggered the onChange event, OR know of a date picker that DOES pass it's name, or even itself to the onChange event so that I can tell which one changed?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  2. #2

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,836

    Re: React - antd - DatePicker - Which one changed?

    Answer - closures to the rescue:

    Code:
        onDateChangeHandler = (id) =>{
            var self = this;
            return function(mmmt, ds){
                self.setState({ [id]: ds })
            }
        }
    and in the loop that sets up teh datepicker:
    Code:
    <DatePicker size='default' name={"date_" + i} onChange={this.onDateChangeHandler("date_" + i)} />
    Baddah boom, baddah bing...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width