如何在Material-UI开关组件标签中创建星号?

huangapple go评论54阅读模式
英文:

How to create asterisk in material-ui switch component lable?

问题

我传递了一个必需的属性,其中包含一个启用标签中的星号符号的属性,但它没有起作用。

<FormControlLabel
    control={
        <Switch
            onChange={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')}
/>
英文:

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

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

答案1

得分: 0

以下是翻译好的内容:

在我决定将自定义组件传递给标签并根据需求启用或禁用星号的条件之后

<FormControlLabel
    control={
        <Switch
            onChange={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')}
/>
英文:

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

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

huangapple
  • 本文由 发表于 2023年7月10日 14:05:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76651024.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定