DateTime Attribute Onchange event in Dynamics Portals

Today’s blog title sounds to be very easy but, there lies something interesting as well. Well continued to work with Dynamics Portals, starting up with entity form and entity form attributes. I have a requirement like to calculate the age on input of date field.

So I am just trying to trigger an onchange event of date field in Entity Form. DateTime Field in entity form is usually a DateTimePicker which is evident to us. My datetime attribute schema name is “new_datefield”. So i tried simply to trigger on change event like

$(‘#new_datefield’).bind(“change”, function() {  alert(“hello i am change event.”);});

Which doesn’t fire the change event. 😦 Simple but not working. After couple of observations over the datetime attribute. DateTime field on click or expand opens up a datetimepicker where actually I need to attach my event handler to it.

To add a custom event handler to datetimepicker if I take the input element and attach event handler which doesnt fire :(. Portals by default allows event bubbling which means instead of attaching an event handler to the actual element, we can attach the same event handler to its parent object.

From the above understandings,

i tried to trigger it using the parent object like

$(“div.control”).find(“[id*=’new_datefield’]”).parent().on(“dp.change”, function (e) {

        alert(e.date); //gives the actual date

        alert(“my change event triggered”);

    });

Hurray 🙂 I am able to trigger/ bind a change event on datetime attribute. Hope it helps. 🙂

 

Advertisements

One thought on “DateTime Attribute Onchange event in Dynamics Portals

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s