- updates and fixes;
This commit is contained in:
@@ -8,7 +8,7 @@ import { FileUpload } from 'primereact/fileupload';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
const Fileupload = ({
|
||||
const FileuploadAsync = ({
|
||||
fieldName,
|
||||
setDataFn,
|
||||
label,
|
||||
@@ -150,4 +150,4 @@ const Fileupload = ({
|
||||
)
|
||||
}
|
||||
|
||||
export default Fileupload;
|
||||
export default FileuploadAsync;
|
||||
41
src/components/FormField/components/Radio/index.js
Normal file
41
src/components/FormField/components/Radio/index.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import React from 'react';
|
||||
import { classNames } from 'primereact/utils';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import { RadioButton } from 'primereact/radiobutton';
|
||||
|
||||
const Radio = ({
|
||||
fieldName,
|
||||
label,
|
||||
control,
|
||||
errors,
|
||||
defaultValue,
|
||||
config = {},
|
||||
infoText = null,
|
||||
options = []
|
||||
}) => {
|
||||
const input = <Controller
|
||||
name={fieldName}
|
||||
control={control}
|
||||
defaultValue={defaultValue}
|
||||
rules={config}
|
||||
render={({ field, fieldState }) =>
|
||||
options.map(o => <div className="appForm__fieldItem" key={o.name}>
|
||||
<RadioButton
|
||||
id={`${fieldName}_${o.name}`}
|
||||
name={fieldName}
|
||||
value={o.name}
|
||||
onChange={(e) => field.onChange(e.value)}
|
||||
checked={field.value === o.name}/>
|
||||
<label htmlFor={`${fieldName}_${o.name}`}>{o.label}</label>
|
||||
</div>)}/>
|
||||
return (
|
||||
<>
|
||||
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
|
||||
{label}{config.required ? '*' : null}
|
||||
</label>
|
||||
{input}
|
||||
{infoText ? <small>{infoText}</small> : null}
|
||||
</>)
|
||||
}
|
||||
|
||||
export default Radio;
|
||||
50
src/components/FormField/components/Select/index.js
Normal file
50
src/components/FormField/components/Select/index.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
import { classNames } from 'primereact/utils';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
|
||||
const Select = ({
|
||||
fieldName,
|
||||
label,
|
||||
control,
|
||||
errors,
|
||||
defaultValue,
|
||||
config = {},
|
||||
infoText = null,
|
||||
inputgroup = false,
|
||||
icon = null,
|
||||
placeholder = '',
|
||||
options = []
|
||||
}) => {
|
||||
const input = <Controller
|
||||
name={fieldName}
|
||||
control={control}
|
||||
defaultValue={defaultValue}
|
||||
rules={config}
|
||||
render={({ field, fieldState }) => (
|
||||
<Dropdown
|
||||
value={field.value}
|
||||
onChange={(e) => field.onChange(e.value)}
|
||||
options={options}
|
||||
optionLabel="label"
|
||||
placeholder={placeholder}
|
||||
className={classNames({ 'p-invalid': fieldState.invalid })}/>
|
||||
)}/>
|
||||
return (
|
||||
<>
|
||||
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
|
||||
{label}{config.required ? '*' : null}
|
||||
</label>
|
||||
{inputgroup
|
||||
? <div className="p-inputgroup flex-1">
|
||||
<span className="p-inputgroup-addon">
|
||||
{icon}
|
||||
</span>
|
||||
{input}
|
||||
</div>
|
||||
: input}
|
||||
{infoText ? <small>{infoText}</small> : null}
|
||||
</>)
|
||||
}
|
||||
|
||||
export default Select;
|
||||
@@ -7,9 +7,11 @@ import TextInput from './components/TextInput';
|
||||
import TextArea from './components/TextArea';
|
||||
import Datepicker from './components/Datepicker';
|
||||
import DatepickerRange from './components/DatepickerRange';
|
||||
import Fileupload from './components/Fileupload';
|
||||
import FileuploadAsync from './components/FileuploadAsync';
|
||||
import NumberInput from './components/NumberInput';
|
||||
import Switch from './components/Switch';
|
||||
import Select from './components/Select';
|
||||
import Radio from './components/Radio';
|
||||
|
||||
const FormField = (props) => {
|
||||
const fields = {
|
||||
@@ -17,9 +19,11 @@ const FormField = (props) => {
|
||||
textarea: TextArea,
|
||||
datepicker: Datepicker,
|
||||
datepickerrange: DatepickerRange,
|
||||
fileupload: Fileupload,
|
||||
fileuploadasync: FileuploadAsync,
|
||||
numberinput: NumberInput,
|
||||
switch: Switch
|
||||
switch: Switch,
|
||||
select: Select,
|
||||
radio: Radio
|
||||
}
|
||||
const Comp = !isNil(fields[props.type]) ? fields[props.type] : null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user