Giter Site home page Giter Site logo

Comments (9)

Dror-Bar avatar Dror-Bar commented on May 18, 2024 1

Would be nice to have access to (e) from onChange e.g. onClick={(e) => onRemove(key)}.
I want to do preventDefault for instance.

from react-tagsinput.

olahol avatar olahol commented on May 18, 2024

Sounds like a great idea, I will add it later today.

from react-tagsinput.

bradennapier avatar bradennapier commented on May 18, 2024

Awesome! I actually found a solution to the problem but i am cheating a bit so this solution would be better. For those using Redux-Form I will post my example below.

Then I am calling a function in the parent component to the form which changes the initial values of the form with the new tags and feeds them back down into this component. It does the job well enough, having extra arguments to show which indexes changed would still be ideal!

Thanks for this component, it's working well for email inputs! The Regex and paste splitting is especially convenient.

const EmailInputField = ({
  fieldProps, 
  addOnPaste = true, 
  onlyUnique = true, 
  label = 'Name', 
  ...props
}) => {

  const { removeField } = fieldProps

  const tagsProps = {
    ...props,
    addOnPaste,
    onlyUnique,
    renderTag: ({tag, key, onRemove, ...other}) => (
      <span key={key} {...other}>
        {tag}
        <a onClick={() => removeField(key)} />
      </span>
    ),
    pasteSplit: data => data.split(',').map(d => d.trim()),
    validationRegex: /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,
  }

  return (
    <div>
      <div className={styles.labelColumn}>
        {label}
      </div>
      <div className={styles.fieldColumnTags}>
          <Tags {...tagsProps} />
      </div>
    </div>
  )

}

from react-tagsinput.

olahol avatar olahol commented on May 18, 2024

Thank you for the example @bradennapier , I'm glad that you like the component 😄

I have added in two more arguments to onChange in version 3.6.2, changed an array of tags that have changed and changedIndexes and array of indexes of the tags that have changed. Hope this will suit your needs.

from react-tagsinput.

bradennapier avatar bradennapier commented on May 18, 2024

Awesome, this is perfect! Much appreciated!

from react-tagsinput.

diessica avatar diessica commented on May 18, 2024

@olahol Isn't it a breaking change? I guess it should be released in a major version.

from react-tagsinput.

olahol avatar olahol commented on May 18, 2024

@diessica You think so? Is adding two extra arguments to onChange breaking? I cant see it unless somebody passes this.setState directly to onChange.

from react-tagsinput.

bradennapier avatar bradennapier commented on May 18, 2024

Or if they were to use spread operators on arguments for some reason when only a single argument was present before. I wouldn't think this is breaking.

from react-tagsinput.

aravindmanikandanpalanisamy avatar aravindmanikandanpalanisamy commented on May 18, 2024

Can you share code for EmailInputField use in redux form Or what data give to fieldProps

from react-tagsinput.

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.