Calendar in form

I have a form and inside it I have some calendar fields, like this:

{ type:“calendar” , name:“fechaCaducidad”, label:“Caducidad”, dateFormat:"%d-%m-%Y %H:%i", labelWidth:“100”, labelHeight:“21”, inputWidth:“110”, inputHeight:“21”, enableTime:true, options:{}, labelLeft:“515”, labelTop:“165”, inputLeft:“515”, inputTop:“186”, position:“absolute” },

I want to save into MySQL but return the field like this:
fechaCaducidad=‘Sun Jan 01 2012 14:57:00 GMT+0100’

But with this format don’t update the table.
What I must do for that field return the calendar info like this: ‘2012-01-03 07:58:06’ ?

Hello ) That’s my first, but definetly NOT the last post here )

I faced same problem in v3, and as urgency of problem didn’t left me any other choices, I’ve developed a fix for it…

It’s quite dirty, but - it works…

		function correctcalendarvalue(pform,pid)
		{
	 		if (pform.itemPull[pform.idPrefix+pid]._type == "calendar" )
			{
				pform.itemPull[pform.idPrefix+pid]._value = pform.getInput(pid).value;
				
			}
		}

		someform.attachEvent("onChange", function (id, value)
		{	
			correctcalendarvalue(someform,id)
		});

PS: Maybe this one eventually will help devs somehow, to trace this error ) It is allmost written in this fix )

PPS: I am working with DX for just a few weeks (my company btw has pro siute bought from them), but during that time I’ve allready had a lots of chances to learn how marvelous this whole project is… And ofcource those guys that are doing it :slight_smile:
Anyway, just wanted to say that guys are doing great job :slight_smile: Keep up the same ways guys, best regards )

Hi Zinger,
Your Workaround is great, thanks for sharing!

But it only works if the calendar is not inside a fieldset or block… For now i placed all my calendars directly on the form - but it would be great if somebody from the DHTMLX-team would write a fix for this problem!?!

/Michael

Ps… Just found out that this one works 100% on Pro, but seems to have some problems with std…
Sorry, but I’ll figure it ou a bit later… no time for now )
And for IE added check for existence (on 7,8 gave me errors…)

[code] function correctcalendarvalue(pform,pid)
{
if (typeof(pform.itemPull[pform.idPrefix+pid]) != ‘undefined’)
{
if (pform.itemPull[pform.idPrefix+pid]._type == “calendar” )
{
pform.itemPull[pform.idPrefix+pid]._value = pform.getInput(pid).value;

				}
			}
		}[/code]

I have made a different workaround.
I am using a beforeUpdate function in my connector file to create a mysql readable date:

function myUpdate($action){ $value = $action->get_value('date'); $new_value = date('Y-m-d', strtotime(substr($value, 4, 11))); //alternative with datetime //$new_value = date('Y-m-d H:i:s ', strtotime(substr($value, 4, 21))); $action->set_value("date",$new_value); } $form->event->attach("beforeUpdate",myUpdate);

I know this is not the best way, but it’s working perfect for me.

thx to MiSchn1 that noticed problems in blocked calendars, i came up with even simplier solution…
And even more dirtier ) But still - works… Now in any conditions…

			function correctcalendarvalue_all(pform,pid)
			{
				if (! pform.isItem("n_"+pid))
				{
					pform._addItem("hidden", "n_"+pid, "");// sId, lp)
				}
				pform.setItemValue("n_"+pid,pform.getInput(pid).value);
			}

All you have to do is catch dates not in “ITEM_NAME” at DB side, but in “N_ITEM_NAME”.
As I said - dirty… But works.

… Can’t edit prev post, so… Some fixes…

			function correctcalendarvalue_all(pform,pid)
			{
				if (pform.getItemType(pid) == "calendar")
				{
					if (! pform.isItem("n_"+pid) )
					{
						pform._addItem("hidden", "n_"+pid, "");// sId, lp)
					}
					pform.setItemValue("n_"+pid,pform.getInput(pid).value);
				}
			}

Hi all

Known problem, alredy fixed.
Updated form/calendar attached.

To test, open demo:
form/samples/02_items/09_calendar.html

myForm.getItemValue(“start_date”) - will give you date object
myForm.getItemValue(“start_date”) - will give you str

also item have param “serverDateFormat”, it specify format
for send/get from server, when “dateFormat” - display in input.
form.rar (240 KB)

  • fix
    myForm.getItemValue(“start_date”, true) - will give you str