|
|
@@ -27,7 +27,7 @@ import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
|
|
|
const filter = createFilterOptions();
|
|
|
|
|
|
async function getPuestoSuperior(puesto, auth) {
|
|
|
- console.log('P:', puesto)
|
|
|
+ // console.log('P:', puesto)
|
|
|
if (puesto.length < 2) return []
|
|
|
let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
|
|
|
let result = await rest.get(auth.token)
|
|
|
@@ -72,7 +72,7 @@ const plazeSchema = Yup.object({
|
|
|
|
|
|
function Edit(props) {
|
|
|
|
|
|
- const { setValue, getValues, reset, control, register, handleSubmit, formState: { errors } } = useForm({
|
|
|
+ const {setValue, getValues, reset, control, register, handleSubmit, formState: { errors } } = useForm({
|
|
|
resolver: yupResolver(plazeSchema),
|
|
|
defaultValues: {
|
|
|
id: 0,
|
|
|
@@ -150,25 +150,38 @@ function Edit(props) {
|
|
|
console.log('value receivied', value)
|
|
|
let id = value?.id || 0;
|
|
|
if (id !== 0) {
|
|
|
- setValue('puestosuperior', id)
|
|
|
- let temp = getValues();
|
|
|
+ console.log('setting value', id)
|
|
|
+ // let temp = getValues();
|
|
|
// temp['puestosuperior'] = id
|
|
|
// temp['puestosuperior_id'] = id
|
|
|
- console.log("TEMP", temp)
|
|
|
- reset({ ...temp, puestosuperior: id })
|
|
|
+ // reset({ ...temp, puestosuperior: id })
|
|
|
+ // setDialogValueHook(value)
|
|
|
+ // reset({ ...temp, puestosuperior_id: id,puestosuperior:value.title })
|
|
|
+ // reset()
|
|
|
+ setValue('puestosuperior', parseInt( id ))
|
|
|
+ // setFocus("notas", { shouldSelect: true })
|
|
|
+ // // resetField('puestosuperior',{keepError:false})
|
|
|
+ //
|
|
|
+
|
|
|
// setDialogValueHook(value)
|
|
|
}
|
|
|
- console.log('SETTING:', value)
|
|
|
+ // console.log('SETTING:', value)
|
|
|
setDialogValueHook(value)
|
|
|
- }, [setValue, reset, getValues])
|
|
|
+ console.log("final", getValues())
|
|
|
+
|
|
|
+ }, [setValue, getValues])
|
|
|
|
|
|
const loading = openSugg && options.length === 0;
|
|
|
|
|
|
const AutoCompleteChange = (event, newValue) => {
|
|
|
- console.log('newValue', newValue)
|
|
|
+ let temp = getValues();
|
|
|
+ console.log('newValue', temp, newValue)
|
|
|
+ temp['puestosuperior'] = newValue?.id;
|
|
|
+ // reset(temp)
|
|
|
+ // setDialogValue(newValue);
|
|
|
+ // return;
|
|
|
//this should be change
|
|
|
- // setValue('puestosuperior', newValue?.id)
|
|
|
-
|
|
|
+ setValue('puestosuperior', newValue?.id)
|
|
|
if (typeof newValue === 'string') {
|
|
|
console.log('if1')
|
|
|
setTimeout(() => {
|
|
|
@@ -251,6 +264,7 @@ function Edit(props) {
|
|
|
tests: temp_test,
|
|
|
puestosuperior: puestosuperior.id
|
|
|
})
|
|
|
+ // console.log("INITIAL:", getValues())
|
|
|
})
|
|
|
.catch(e => console.log(e))
|
|
|
|
|
|
@@ -383,89 +397,87 @@ function Edit(props) {
|
|
|
{...register("nombrepuesto")} />
|
|
|
|
|
|
|
|
|
- {/*
|
|
|
- <FormControl fullWidth>
|
|
|
+ <FormControl fullWidth>
|
|
|
<Controller
|
|
|
helperText={errors.puestosuperior?.message}
|
|
|
error={errors?.puestosuperior}
|
|
|
name="puestosuperior"
|
|
|
control={control}
|
|
|
- render={({ field }) =>
|
|
|
- <Autocomplete
|
|
|
- fullWidth
|
|
|
- value={dialogValue}
|
|
|
- onChange={AutoCompleteChange}
|
|
|
- open={openSugg}
|
|
|
- onOpen={() => {
|
|
|
- setOpenSugg(true);
|
|
|
- }}
|
|
|
- onClose={() => {
|
|
|
- setOpenSugg(false);
|
|
|
- }}
|
|
|
- isOptionEqualToValue={(option, value) => option.title === value.title}
|
|
|
- filterOptions={(options, params) => {
|
|
|
- const filtered = filter(options, params);
|
|
|
-
|
|
|
- if (params.inputValue !== '') {
|
|
|
- filtered.push({
|
|
|
- inputValue: params.inputValue,
|
|
|
- title: `Agregar "${params.inputValue}"`,
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- return filtered;
|
|
|
- }}
|
|
|
- id="puesto_superior_autocomplete"
|
|
|
- options={options}
|
|
|
- loading={loading}
|
|
|
- getOptionLabel={(option) => {
|
|
|
- if (typeof option === 'string') {
|
|
|
- return option;
|
|
|
- }
|
|
|
- if (option.inputValue) {
|
|
|
- return option.inputValue;
|
|
|
- }
|
|
|
- return option.title;
|
|
|
- }}
|
|
|
- selectOnFocus
|
|
|
- clearOnBlur
|
|
|
- handleHomeEndKeys
|
|
|
- renderOption={(props, option) => <li key={option.id} {...props}>{option.title}</li>}
|
|
|
- freeSolo
|
|
|
- renderInput={(params) => (
|
|
|
- <TextField
|
|
|
- {...params}
|
|
|
- {...register('puestosuperior')}
|
|
|
- error={Boolean(errors.puestosuperior)}
|
|
|
- label="Puesto Superior"
|
|
|
- InputProps={{
|
|
|
- ...params.InputProps,
|
|
|
- onChange: (event) => {
|
|
|
- // let title = event.target.value;
|
|
|
- // console.log('titulo',title)
|
|
|
- setOptions([]);
|
|
|
- setDialogValue({
|
|
|
- title: event.target.value,
|
|
|
- id: '',
|
|
|
+ render={({ field }) =>
|
|
|
+ <Autocomplete
|
|
|
+ fullWidth
|
|
|
+ value={dialogValue}
|
|
|
+ onChange={AutoCompleteChange}
|
|
|
+ open={openSugg}
|
|
|
+ onOpen={() => {
|
|
|
+ setOpenSugg(true);
|
|
|
+ }}
|
|
|
+ onClose={() => {
|
|
|
+ setOpenSugg(false);
|
|
|
+ }}
|
|
|
+ isOptionEqualToValue={(option, value) => option.title === value.title}
|
|
|
+ filterOptions={(options, params) => {
|
|
|
+ const filtered = filter(options, params);
|
|
|
+
|
|
|
+ if (params.inputValue !== '') {
|
|
|
+ filtered.push({
|
|
|
+ inputValue: params.inputValue,
|
|
|
+ title: `Agregar "${params.inputValue}"`,
|
|
|
});
|
|
|
- },
|
|
|
- endAdornment: (
|
|
|
- <React.Fragment>
|
|
|
- {loading ? <CircularProgress color="inherit" size={20} /> : null}
|
|
|
- {params.InputProps.endAdornment}
|
|
|
- </React.Fragment>
|
|
|
- ),
|
|
|
+ }
|
|
|
+
|
|
|
+ return filtered;
|
|
|
}}
|
|
|
- />
|
|
|
- )}
|
|
|
+ id="puesto_superior_autocomplete"
|
|
|
+ options={options}
|
|
|
+ loading={loading}
|
|
|
+ getOptionLabel={(option) => {
|
|
|
+ if (typeof option === 'string') {
|
|
|
+ return option;
|
|
|
+ }
|
|
|
+ if (option.inputValue) {
|
|
|
+ return option.inputValue;
|
|
|
+ }
|
|
|
+ return option.title;
|
|
|
+ }}
|
|
|
+ selectOnFocus
|
|
|
+ clearOnBlur
|
|
|
+ handleHomeEndKeys
|
|
|
+ renderOption={(props, option) => <li key={option.id} {...props}>{option.title}</li>}
|
|
|
+ freeSolo
|
|
|
+ renderInput={(params) => (
|
|
|
+ <TextField
|
|
|
+ {...params}
|
|
|
+ {...register('puestosuperior')}
|
|
|
+ error={Boolean(errors.puestosuperior)}
|
|
|
+ label="Puesto Superior"
|
|
|
+ InputProps={{
|
|
|
+ ...params.InputProps,
|
|
|
+ onChange: (event) => {
|
|
|
+ let title = event.target.value;
|
|
|
+ console.log('titulo',title)
|
|
|
+ setOptions([]);
|
|
|
+ setDialogValue({
|
|
|
+ title: event.target.value,
|
|
|
+ id: '',
|
|
|
+ });
|
|
|
+ },
|
|
|
+ endAdornment: (
|
|
|
+ <React.Fragment>
|
|
|
+ {loading ? <CircularProgress color="inherit" size={20} /> : null}
|
|
|
+ {params.InputProps.endAdornment}
|
|
|
+ </React.Fragment>
|
|
|
+ ),
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
|
|
|
/>
|
|
|
|
|
|
}
|
|
|
- >
|
|
|
- </Controller>
|
|
|
- </FormControl>
|
|
|
- */}
|
|
|
+ >
|
|
|
+ </Controller>
|
|
|
+ </FormControl>
|
|
|
|
|
|
</Stack>
|
|
|
|