Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Display weekday name in subgrid.

Questions related to using nuBuilder Forte.
Post Reply
amit
Posts: 36
Joined: Sat Jun 02, 2018 1:26 pm

Display weekday name in subgrid.

Unread post by amit »

Hi guys,
I have a subgrid which contains dates in the first column. In the 2nd column I'd like to display the weekday (e.g. Monday) if the date is changed. How do I do that?
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Display weekday name in subgrid.

Unread post by kev1n »

Hi,

Add an onchange event to your date field and paste this JavaScript into your form's Custom Code.

Code: Select all

function dayName(date) {
	var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
	return days[new Date(date).getDay()];
}

function dateChanged(event) {

	var id = event.target.id;
	var date = $('#' + String(id)).val();
	row = $('#' + String(id)).attr('data-nu-prefix').slice(-3);
	$("#sf_obj_id" + row + "sf_dayname").val(dayName(date)).change();

}
You do not have the required permissions to view the files attached to this post.
amit
Posts: 36
Joined: Sat Jun 02, 2018 1:26 pm

Re: Display weekday name in subgrid.

Unread post by amit »

It doesn't work for me - no weekday is shown :(
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Display weekday name in subgrid.

Unread post by kev1n »

The function must be passed a valid date, which can be parsed. Otherwise it must be converted before.
amit
Posts: 36
Joined: Sat Jun 02, 2018 1:26 pm

Re: Display weekday name in subgrid.

Unread post by amit »

That did the trick - thx kev1n :D
Post Reply