Cleave.js: How to use with material-ui TextField and React-Final-Form?

Created on 12 Apr 2018  路  7Comments  路  Source: nosir/cleave.js

I want use material-ui TextField like skin for Cleave and RFF for form. Can you help me?

import React from "react";
import Cleave from "cleave.js/react";
import TextField from "material-ui/TextField";

export default ({
  input: { name, onChange, value, ...restInput },
  meta,
  ...rest
}) => (
  <TextField
    {...rest}
    name={name}
    helperText={meta.touched ? meta.error : undefined}
    error={meta.error && meta.touched}
    inputProps={restInput}
  >
    <Cleave name={name} onChange={onChange} value={value}/>
  </TextField>
);

All 7 comments

Also curious about an example of integrating cleave with react-final-form

I'm interested too

@bogdansoare @ofarukcaki

import React from "react";
import Cleave from "cleave.js/react";
import { TextField } from "@material-ui/core";

function MaskedTextField(props) {
  const { options, inputRef, ...other } = props;
  return <Cleave {...other} ref={inputRef} options={options} />;
}

export default ({
  input: { name, onChange, value, ...restInput },
  meta,
  options,
  ...rest
}) => 
    <TextField
      {...rest}
      name={name}
      onChange={onChange}
      value={value}
      error={meta.error && meta.touched}
      helperText={meta && meta.touched ? meta.error : undefined}
      inputProps={{ ...restInput, options, value }}
      InputProps={{
        inputComponent: MaskedTextField
      }}
    />
  );
};

Need create adapter with cleave.js.
CleaveTextField it is adapter like in example in RFF.

Thanks @Popugune I also added this to the document

Is there a way to keep the Material-UI design. I mean I did exactly like in your example but the input rendered wasn't anything like the material-UI input.

asdasdasdasdasdad

I found this one https://codesandbox.io/s/z65pjx3m1x?from-embed that helped me with material-ui

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CaptainYarb picture CaptainYarb  路  3Comments

shaileshrathod128 picture shaileshrathod128  路  6Comments

melbon picture melbon  路  3Comments

fcoms picture fcoms  路  3Comments

dan-kez picture dan-kez  路  5Comments