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
2 months 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]
2 months 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
2 months 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>

Comment posted by Dan Letecky [DayPilot]
2 months ago.

The field labels can only be specified using plain text (the name value gets HTML-encoded automatically).

If you want to display custom HTML, you will need to insert another type: "html" field.

const form = [
  { html: "your HTML", type: "html" },
  // ...
];
Comment posted by Gavin
2 months ago.

Thanks

Comment posted by Gavin
2 months ago.

If I do this I presume that I have to have replaced the type: “radio” and build the whole form using html. Is that correct?

Answer posted by Gavin
2 months ago.

ignore that. I worked it out. thanks

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.