如何在Wordpress中的自定义Gutenberg编辑器块中进行输入验证?

问题描述

我想对edit函数中src和figcaption属性中的用户输入进行一些检查。我一直在环顾四周,但没有发现任何有用的东西。

也许我还需要在保存功能中进行检查?我认为,尽管在编辑功能中检查了输入后,这是多余的。

registerBlockType('gutenberg-examples/example-01-basic-esnext',{
    attributes: {
        src: {
            type: 'string'
        },figcaption: {
            type: 'string'
        }
    },edit({attributes,setAttributes}) {
        const onChange = (e) => setAttributes({[e.target.name]: e.target.value})

        return (
            <form>
                <header>example-01-basic-esnext</header>
                <input style={{width: '100%',marginBottom: '1rem'}}
                       type="text"
                       value={attributes.src}
                       onChange={onChange}
                       name="src"
                       placeholder="src"/>
                <br></br>
                <input style={{width: '100%'}}
                       type="text"
                       value={attributes.figcaption}
                       onChange={onChange}
                       name="figcaption"
                       placeholder="figcaption"/>
            </form>
        );
    },...
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)