Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是的,验证,helperText添加到MaterialUI输入组件_Javascript_Reactjs_Yup - Fatal编程技术网

Javascript 是的,验证,helperText添加到MaterialUI输入组件

Javascript 是的,验证,helperText添加到MaterialUI输入组件,javascript,reactjs,yup,Javascript,Reactjs,Yup,我正在使用材质UI接受文件类型和上载文件,我正在尝试将Yup验证与此集成,但是输入不允许在其定义中使用helperText,它允许出现错误,取消上载时会报告红色下划线,如何将helperText值添加到输入中并接收错误消息 <FormControl className={classes.margin}> <Input className={classes.fileUpload}

我正在使用材质UI接受文件类型和上载文件,我正在尝试将Yup验证与此集成,但是输入不允许在其定义中使用helperText,它允许出现错误,取消上载时会报告红色下划线,如何将helperText值添加到输入中并接收错误消息

<FormControl className={classes.margin}>
                      <Input
                        className={classes.fileUpload}
                        type="file"
                        id="file"
                        onChange={onSelectFile}
                        name="file"
                        inputProps={fileRestrict}
                        error={touched.file && Boolean(errors.file)}
                        helperText={touched.file ? errors.file : ''}
                      />
                    </FormControl>

我的validationSchema通过道具从物料UI文本字段文档中传入-

高级配置: 了解文本字段是以下组件之上的简单抽象非常重要:FormControl、InputLabel、FilleInput、OutlineInput、Input、FormHelperText

您正在尝试使用FormHelperText组件,但是您使用的输入组件不包含FormHelperText组件作为子组件。您可以单独使用FormHelperText组件作为同级组件,也可以使用TextField组件并相应地进行配置。许多相同的道具被传给输入组件。但是,您可以使用TextField的InputProps属性直接传递任何其他内容。注意:这是区分大小写的,小写i影响HTML输入元素,大写i影响材质UI输入组件

<TextField 
  className={classes.margin}
  type="file"
  error={touched.file && Boolean(errors.file)}
  helperText={touched.file ? errors.file : ''}
  onChange={onSelectFile}
  InputProps={{className: classes.fileUpload}}
  inputProps={{id: "file"}}
/>
helperText={touch.file?errors.file:'您的消息在这里'}您有空字符串呈现
<TextField 
  className={classes.margin}
  type="file"
  error={touched.file && Boolean(errors.file)}
  helperText={touched.file ? errors.file : ''}
  onChange={onSelectFile}
  InputProps={{className: classes.fileUpload}}
  inputProps={{id: "file"}}
/>