search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to get response to a radio form

Asked by Gavin
4 days ago.

I have added the code below to popup a form with three options and I’m capturing the result of my selection in modal.result.

The form displays correctly:

But based on my code I expect modal.result to be A, B or C based on my selection. Instead I get this when I display modal.result:

What am I doing wrong?

if (data.msg.addbrand && data.msg.addbrand != '') {

	var msg = 'The brand ' + brand + ' is unknown.  What would you like to do?';
	const resources = [
		{ name: "  Accept item and add brand", id: "A" },
		{ name: "  Accept item but do not add brand", id: "B" },
		{ name: "  Cancel", id: "C" },
	];
	
	const form = [
		{
		  name: msg,
		  id: "resource",
		  options: resources,
		  type: "radio",
		},
	];

	const data = {
		resource: "A",
	};

	(async function() {
		const modal = await DayPilot.Modal.form(form, data);
		alert(modal.result);
		if (modal.result == 'A') {
			var addbrand = "yes";
			acceptitemconfirmed1(addbrand);
		} else if (modal.result == 'B') {
			var addbrand = "no";
			acceptitemconfirmed1(addbrand);
		} else {	
			$(location).attr("href", "item_edit_review.php?id="+item_id);
		}
	})();
	
} else {
	addbrand = "no";
	acceptitemconfirmed1(addbrand);
}	
Answer posted by Dan Letecky [DayPilot]
1 day ago.

In this case, modal.result holds a copy of the data object. Its properties are set according to the user selection.

So, in order to get the radio selection, you need to read modal.result.resource.

To inspect the object, you can print it to the console like this:

console.log(“modal.result”, modal.result);
Comment posted by Gavin
23 hours ago.

Thanks. that helps a lot. Can I ask one more thing? I’m using the name parameter for the ‘question’? How do I insert a line break or space in it. It doesn’t resolve normal html entities like <br>

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):