Extended search with startup script

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
innovativeshadow
User
Posts: 86
Location: Almaty, Kazakhstan

Extended search with startup script

Post 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?


arbei
User
Posts: 9440

Post by arbei »

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


innovativeshadow
User
Posts: 86
Location: Almaty, Kazakhstan

Post 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");

arbei
User
Posts: 9440

Post 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.


innovativeshadow
User
Posts: 86
Location: Almaty, Kazakhstan

Post 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);
        }
	}

}

arbei
User
Posts: 9440

Post 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).

Post Reply