Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, I have been struggling with this for days now. I am trying to pass a variable to the action function to update app metafields on a submit button click. No matter which way I try, I am always getting back an error relating to the passed variable being null. This is the code I have:
The button click:
const handleSubmit = async () => {
const dateValue = textFieldValue;
console.log('after key presses: '+dateValue);
submit( {variables: { myKey: dateValue }} , { replace: true, method: "post" });
}
and here is the code for the submit action:
export const action = async ({ request, myKey }) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CreateAppDataMetafield($metafieldsSetInput: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafieldsSetInput) {
metafields {
id
namespace
value
key
}
userErrors {
field
message
}
}
}`,
{
variables: {
"metafieldsSetInput": [
{
"namespace": "settings-attributes",
"key": "date-available",
"type": "boolean",
"value": "false",
"ownerId": globalAppId
},
{
"namespace": "settings-attributes",
"key": "date",
"type": "single_line_text_field",
"value": myKey,
"ownerId": globalAppId
}
]
},
},
);
const data = await response.json();
return json({
data,
});
};
If anyone has any ideas, I would be VERY grateful. Thanks
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024