tcomb-form-native icon indicating copy to clipboard operation
tcomb-form-native copied to clipboard

Allow list values to be raw strings. Fixes #289

Open fiznool opened this issue 6 years ago • 1 comments

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.
  }
}

fiznool avatar Mar 28 '18 10:03 fiznool

@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)

compojoom avatar Nov 06 '18 14:11 compojoom