skip to Main Content

I’m passing a required props has a property to enable asterisk symbol in label but it not working

<FormControlLabel
    control={
        <Switch
            onChange={useCallback(event =>
                onChangeRow(
                    rowIndex,
                    'name',
                    event.target.checked === true ? 'Y' : 'N'
                )
            )}
            disableRipple
            style={{ backgroundColor: 'transparent' }}
            checked={row.address.name === 'Y'}
            color='primary'
        />
    }
    labelPlacement='start'
    label={'Name?'}
    required={row.formDesc.name.is_mandatory === 'Y'}
    disabled={issubmited.value ? disabled : row.formDesc.name.is_editable === 'N'}
    error={hasError('name')}
    helpertext={getError('name')}
/>

2

Answers


  1. Chosen as BEST ANSWER

    After I have dicidied to pass custom compoenent to the lable with condition to enable disable asterisk depends on requirement.

    <FormControlLabel
        control={
            <Switch
                onChange={useCallback(event =>
                    onChangeRow(
                        rowIndex,
                        'name',
                        event.target.checked === true ? 'Y' : 'N'
                    )
                )}
                disableRipple
                style={{ backgroundColor: 'transparent' }}
                checked={row.address.name === 'Y'}
                color='primary'
            />
        }
        labelPlacement='start'
        label={<Typography>Name?{row.formDesc.name.is_mandatory === 'Y' && <span style={{color: 'red', fontSize: '18px'}}>*</span>}</Typography>}
        required={row.formDesc.name.is_mandatory === 'Y'}
        disabled={issubmited.value ? disabled : row.formDesc.name.is_editable === 'N'}
        error={hasError('name')}
        helpertext={getError('name')}
    />
    

  2. I have a question, why don’t you pass the second argument to useCallback but still use it?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search