How to add custom clear button on Relate Field?

Hello Everyone, I would like to ask if it is possible to add a custom clear button on relate field?


This is what I wanted.

  • If you click clear button on Province field it will clear the value of Province, City and Barangay
  • If you click clear button on CIty field it will clear the value of City and Barangay
  • No modification needed for Barangay clear button

In SuiteCRM, For add custom changes on the clear button then you need to update below files.

File Path: custom/Extension/application/Ext/LogicHooks/CustomLogicHook.php

Add below code on CustomLogicHook.php

File Path: custom/include/CustomLogicHook/CustomLogicHook.php

Add below code on CustomLogicHook.php

File Path: custom/include/CustomLogicHook.js

Add below code on CustomLogicHook.js

1 Like

@jessica1 , its working now. Thank you. I want to do another modification on the relate field buttons


This is what I wanted

  • City and Barangay pop up button will be disabled if the province field is empty
  • Barangay pop up button will be disabled also if the city field is empty

Can I can implement it also using this approach?

@jessica1 , I was able to implement disabled/enabled button if a certain field is/are empty. But it is not working on a relate field., if it just a normal field where you are manually inputted the data this codes below works.

$("#btn_custom_city_c").attr("disabled", true);
$("#btn_custom_barangay_c").attr("disabled", true);
$('#custom_province_c').keyup(function() {
    if ($(this).val().length !=0)
        $("#btn_custom_city_c").attr("disabled", false);
    else
        $("#btn_custom_city_c").attr("disabled", true);
});

In SuiteCRM, For enable/disable Related Field follow below code ,

if($(’#province_c’).val() == “”){

$("#btn_city_c").attr(“disabled”, true);

$("#btn_barangay_c").attr(“disabled”, true);

}else{

$("#btn_city_c").attr(“disabled”, false);

$("#btn_barangay_c").attr(“disabled”, false);

}

if($(’#city_c’).val() == “”){

$("#btn_barangay_c").attr(“disabled”, true);

}else{

$("#btn_barangay_c").attr(“disabled”, false);

}

var inputName = “input[name=‘province_c’]”;

YAHOO.util.Event.addListener(YAHOO.util.Selector.query(inputName), ‘change’, function(){

$("#btn_city_c").attr(“disabled”, false);

});

var inputName = “input[name=‘city_c’]”;

YAHOO.util.Event.addListener(YAHOO.util.Selector.query(inputName), ‘change’, function(){

$("#btn_barangay_c").attr(“disabled”, false);

});

$(’#btn_clr_province_c’).on(‘click’, function(){

SUGAR.clearRelateField(this.form,‘city_c’,‘city_id_c’);

SUGAR.clearRelateField(this.form,‘barangay_c’,‘barangay_id_c’);

$("#btn_city_c").attr(“disabled”, true);

$("#btn_barangay_c").attr(“disabled”, true);

});

$(’#btn_clr_city_c’).on(‘click’, function(){

SUGAR.clearRelateField(this.form,‘barangay_c’,‘barangay_id_c’);

$("#btn_barangay_c").attr(“disabled”, true);

});

See the below screenshots,

@jessica1 , its working now, thank you very much.

1 Like