How to put <PlainText> and <Button> components inside <Form> in Gutenberg block

admin2025-06-03  3

I am writing a block where I need to render a form inside the editor. This is how I tried it:

edit: function( props ) {
        return(
            <Form
                method="get"
                className="search-form"
                <PlainText
                    title="search box"
                    placeholder="Search"
                    className="search-field"
                    type="text"
                    name="s"
                    readonly="true"
                />
                <PlainText
                    type="hidden"
                    name="type"
                    value="media"
                />
                <Button
                    type="submit"
                    title="search site"
                    className="search-submit"
                    value="&rsaquo;"
                    disabled="disabled"
                />
            />
        );
    },

But the watcher is complaining with the following (screenshot attached)

what is the right way to do it?

I am writing a block where I need to render a form inside the editor. This is how I tried it:

edit: function( props ) {
        return(
            <Form
                method="get"
                className="search-form"
                <PlainText
                    title="search box"
                    placeholder="Search"
                    className="search-field"
                    type="text"
                    name="s"
                    readonly="true"
                />
                <PlainText
                    type="hidden"
                    name="type"
                    value="media"
                />
                <Button
                    type="submit"
                    title="search site"
                    className="search-submit"
                    value="&rsaquo;"
                    disabled="disabled"
                />
            />
        );
    },

But the watcher is complaining with the following (screenshot attached)

what is the right way to do it?

Share Improve this question asked Feb 7, 2019 at 6:52 Subrata SarkarSubrata Sarkar 2395 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

When an element doesn't have children it can be self-closing:

<Something something="123" />

Otherwise it needs to behave like normal html tag with an opening part: <Something> and a closing one: </Something>

edit: function( props ) {
    return(
        <Form
            method="get"
            className="search-form"
        >
            <PlainText
                title="search box"
                placeholder="Search"
                className="search-field"
                type="text"
                name="s"
                readonly="true"
            />
            <PlainText
                type="hidden"
                name="type"
                value="media"
            />
            <Button
                type="submit"
                title="search site"
                className="search-submit"
                value="&rsaquo;"
                disabled="disabled"
            />
        </Form>
    );
},
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748935340a314960.html

最新回复(0)