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

Allow list values to be raw strings. Fixes #289 #469

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fiznool
Copy link

@fiznool fiznool commented Mar 28, 2018

This fixes two separate issues, both to do with setting a custom template for a tcomb list type.

The result is that you can use the following schema & options:

const schema = {
  photos: tComb.list(tComb.String)
};

const options = {
  fields: {
    photos: {
      // Set a custom template for the list
      template: MultiPhotoTemplate
    }
  }
};

with the following template:

class MultiPhotoTemplate extends React.Component {
  render() {
    const { value } = this.props;
    // Here, 'value' is an array of strings, so do what you need to do with them.
    // To update the form field, call `this.props.onChange(newValue)`, where
    // `newValue` is an array of strings.
  }
}

@compojoom
Copy link
Contributor

@alvaromb - I was getting an error with the following code
const tPosition = t.struct({
latitude: latitude,
longitude: longitude
})
const model = t.struct({
polygon: t.maybe(t.list(tPosition)),
})

with the changes from this pull request it works as expected and my polygon is being properly validated (or at least doesn't trigger an error)

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

Successfully merging this pull request may close these issues.

2 participants