What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to Debug a Shopify Custom Embedded App?

How to Debug a Shopify Custom Embedded App?

Ekk0
Shopify Partner
9 0 0

I want to develop a custom app for my store, which is embedded. During the initialization process, I realized that I don't know how to debug it. For example, now in VS Code, I want to submit a form and print the form data to the console before submitting it to check if the data is correct. However, I can't see anything in the browser's console, and clicking the two buttons doesn't have any effect.

 

I noticed that the embedded app is displayed in the browser as an iframe. Can someone tell me how to debug it? I would greatly appreciate it.

 

In CodeSandbox, the button click functionality in this code works correctly, but in the Shopify admin, it doesn't have any effect.

Ekk0_0-1720075457103.png

 

Ekk0_1-1720075473434.png

 

Here is my code:

 

import { Page, Form, FormLayout, TextField, ButtonGroup, Button } from '@shopify/polaris';
import React, { useState, useCallback } from 'react';

export default function Settings() {
    const [tagsValue, setTagsValue] = useState('');

    const handleChange = useCallback(
        newValue => setTagsValue(newValue),
        [],
    );

    const handleSubmit = () => {
        console.log('Submitted tagsValue:', tagsValue);
        alert(123)
    }

    return (
        <Page>
            <Form onSubmit={handleSubmit}>
                <FormLayout>
                    <TextField label="tags_01" onChange={handleChange} value={tagsValue} autoComplete="off" />
                </FormLayout>
                <ButtonGroup>
                    <Button onClick={() => setTagsValue('')}>Cancel</Button>
                    <Button primary onClick={handleSubmit}>Save</Button>
                </ButtonGroup>
            </Form>
        </Page>
    );
}

 

Replies 2 (2)

SomeUsernameHe
Shopify Partner
517 57 110
import { Page, Form, FormLayout, TextField, ButtonGroup, Button } from '@shopify/polaris';
import React, { useState, useCallback } from 'react';

export default function Settings() {
    const [tagsValue, setTagsValue] = useState('');

    const handleChange = useCallback(
        (event) => setTagsValue(event.target.value),
        [],
    );

    const handleSubmit = (event) => {
        event.preventDefault(); // Prevent default form submission behavior
        console.log('Submitted tagsValue:', tagsValue);
        // Implement submission logic here
    }

    return (
        <Page>
            <Form onSubmit={handleSubmit}>
                <FormLayout>
                    <TextField label="tags_01" onChange={handleChange} value={tagsValue} autoComplete="off" />
                </FormLayout>
                <ButtonGroup>
                    <Button onClick={() => setTagsValue('')}>Cancel</Button>
                    <Button primary submit>Save</Button>
                </ButtonGroup>
            </Form>
        </Page>
    );
}

 

This should work. Also, if you are using VS Code and running your app there, you should see something in the terminal inside VS Code. 

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee
Ekk0
Shopify Partner
9 0 0

I tried the code you posted. After clicking the save button, some prompts appear, but the printed information still does not show up anywhere. The cancel button's event is also not triggered.

Ekk0_0-1720080362316.png

I added a console event to the cancel button as well, but it is still not being triggered.

 

// import { Page, Form, FormLayout, TextField, ButtonGroup, Button } from '@shopify/polaris';
// import React, { useState, useCallback } from 'react';

// export default function Settings() {
//     const [tagsValue, setTagsValue] = useState('');

//     const handleChange = useCallback(
//         newValue => setTagsValue(newValue),
//         [],
//     );

//     const handleSubmit = () => {
//         console.log('Submitted tagsValue:', tagsValue);
//         alert(123)
//     }

//     return (
//         <Page>
//             <Form onSubmit={handleSubmit}>
//                 <FormLayout>
//                     <TextField label="tags_02" onChange={handleChange} value={tagsValue} autoComplete="off" />
//                 </FormLayout>
//                 <ButtonGroup>
//                     <Button onClick={() => setTagsValue('')}>Cancel</Button>
//                     <Button primary onClick={handleSubmit}>Save</Button>
//                 </ButtonGroup>
//             </Form>
//         </Page>
//     );
// }

import { Page, Form, FormLayout, TextField, ButtonGroup, Button } from '@shopify/polaris';
import React, { useState, useCallback } from 'react';

export default function Settings() {
    const [tagsValue, setTagsValue] = useState('');

    const handleChange = useCallback(
        (event) => setTagsValue(event.target.value),
        [],
    );

    const handleSubmit = (event) => {
        event.preventDefault(); // Prevent default form submission behavior
        console.log('Submitted tagsValue:', tagsValue);
        // Implement submission logic here
    }
    const cancel = useCallback(
        () => setTagsValue(""),
        [],
    );
    return (
        <Page>
            <Form onSubmit={handleSubmit}>
                <FormLayout>
                    <TextField label="tags_04" onChange={handleChange} value={tagsValue} autoComplete="off" />
                </FormLayout>
                <ButtonGroup>
                    <Button onClick={cancel}>Cancel</Button>
                    <Button primary submit>Save</Button>
                </ButtonGroup>
            </Form>
        </Page>
    );
}