Page 1 of 1

Extended search with startup script

Posted: Sun Mar 19, 2023 2:01 am
by innovativeshadow

When I enable Extended search on a field which i used in startup script

example:

$("#x_payBy").change(function() { ..... });

This code seams will not work if the extended search for payBy is enabled.

any solution for this?


Re: Enabling extended search on a field breaking the startup script event

Posted: Sun Mar 19, 2023 9:51 am
by arbei

Your code may or may not work depending on the Edit Tag of the field. You better use Client Side Events instead.


Re: Enabling extended search on a field breaking the startup script event

Posted: Sun Mar 19, 2023 2:31 pm
by innovativeshadow

My code is under Client Scripts->Table Specific->Add/Copy page->Startup Script.

Tested the the code by enabling the Extended search and disabling the extended search.

The client script is not working when I enable the Extended search on the change function field.

My sample code:

$("#x_payBy").change(function() {
    if (this.value == 'CH'){
        $('#x_baID').empty();
        $('#r_baID').hide();
    } else if (this.value == 'TT') {
        $('#x_baID').empty();
        $('#r_baID').show();
    } else if (this.value == 'CD') {
        $('#x_baID').empty();
        $('#r_baID').show();
    } else if (this.value == 'CR') {
        $('#x_baID').empty();
        $('#r_baID').hide();
	} else {
        $('#r_baID').hide();
	}
});
$("#x_payBy").triggerHandler("change");

Re: Enabling extended search on a field breaking the startup script event

Posted: Sun Mar 19, 2023 2:41 pm
by arbei

innovativeshadow wrote:

My code is under Client Scripts->Table Specific->Add/Copy page->Startup Script.

Extended Search is in the List page.

If you use Client Side Events, it should work in all pages. You may also use the .visible() method of jQuery .fields() Plugin in client side events.

To check JavaScript error, press F12 in your browser and go to the Console panel.


Re: Extended search with startup script

Posted: Sun Mar 19, 2023 4:42 pm
by innovativeshadow

In the below code

  1. The Start with field hide is not working as in Startup script.
  2. Cannot empty the value on change.
  3. Alternatively used disabled, but when the validation script returned false, the field is visible&/its enabled again if disabled.

Not a best place it seems to use a client script for manipulating fields.

{ // keys = event types, values = handler functions
	"change": function(e) {
		$row = $(this).fields();
		if ($row["payBy"].value() == 'CH'){
			$(this).fields("baID").value("");
			$(this).fields("baID").visible(false);
        } else if ($row["payBy"].value() == 'TT') {
        	$(this).fields("baID").disabled(false);
        	$(this).fields("baID").visible(true);
        } else if ($row["payBy"].value() == 'CD') {
        	$(this).fields("baID").disabled(false);
        	$(this).fields("baID").visible(true);
        } else if (this.value == 'CR') {
        	$(this).fields("baID").disabled(true);
        	$(this).fields("baID").visible(false);
        } else {
        	$(this).fields("baID").disabled(true);
        	$(this).fields("baID").visible(false);
        }
	}

}

Re: Extended search with startup script

Posted: Sun Mar 19, 2023 5:27 pm
by arbei
  1. You checked $row["payBy"].value() but then check this.value, make sure they are correct,
  2. If you hide the field, there is no need to disable the field, otherwise no field value for the disabled field is submitted, it may cause problem if the field is required by the table (or the field will be set to empy in Edit page).