简体   繁体   中英

How to serialize lookup field in jQuery CRM Dynamics Portal

I have a form with textboxes and lookup fields in CRM dynamics adx portal.

For validation I want to only enable the submit button when text is changed in any field otherwise keep it disabled.

I am able to achieve this by serializing all the fields in the form with the following code but the lookup fields do not get serialized and stay in a read-only state:

$(document).ready(function  () {
    $(".text.form-control").each(function(){
        $(this).data('serialized', $(this).serialize());
    })
    .on('change input', function(){
        $(':input[type="button"]').prop('disabled', $(this).serialize() == $(this).data('serialized'));
           
     });
     $(':input[type="button"]').prop('disabled', true);
});

How do I include lookup fields to be serialized as well?

To solve this, two changes are needed:

Instead of serializing just the textboxes, serialize the entire form, in my case this would include the lookup form-content, changing the second line of the code would serialize all field types on the form.

Also, to avoid disabling the lookup buttons specify the button you want to disable by value not type. type='button' also belongs to the lookup popup select button which I don't want to disable, I needed to disable just the Submit and Cancel buttons when no changes occurred, so I used the value properties of those two buttons:

$(document).ready(function  () {
$("form").each(function(){
    $(this).data('serialized', $(this).serialize());
})
.on('change input', function(){
    $(':input[value="Submit Request"]').prop('disabled', $(this).serialize() == $(this).data('serialized'));
    $(':input[value="Cancel"]').prop('disabled', $(this).serialize() == $(this).data('serialized'));
 });
 $(':input[value="Submit Request"]').prop('disabled', true);
 $(':input[value="Cancel"]').prop('disabled', true); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM