Reset autofill value

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
sangnandar
User
Posts: 980

Reset autofill value

Post by sangnandar »

I have a form with 2 fields:
(1) ref <--- to a lookup_table
(2) label <--- autofill column

MySQL query works fine.
ew_Ajax works fine.
I can autofill field label by selecting value form ref.

My problem:
When I set ref to default (set it back to "Please Select" option from dropdown menu), I need to get an empty label.
How to reset the autofill value to be empty?
I try !== null , !== "", with no success.}
var result = ew_Ajax(bla..bla..bla..)
if (result === null) {$label_value = "" ;} <--- not working
if (result === "") {$label_value = "" ;} <--- not working

Thanks.


sangnandar
User
Posts: 980

Post by sangnandar »

I solved my case.
Here is the summary, hope it will helps someone else.

My case is exactly the same as Help File Lookup Table -> Ajax by Server Events and Client Scripts -> Example 1: Auto-Fill synchronously

Page_Load server event for Add Page:
ew_SetClientVar("MyCustomSql", ew_Encrypt("SELECT UnitPrice FROM products WHERE ProductID = {query_value}"));

Startup Script for Add Page to attach onchange event: (JavaScript):
$("#x_ProductID").change(function() {
var result = ew_Ajax(ewVar.MyCustomSql, $(this).val());
$("#x_UnitPrice").val(result);
});

I try this:
$("#x_ProductID").change(function() {
var get_data = ew_Ajax(ewVar.MyCustomSql, $(this).val());
if (get_data !== "") {var data = "something"} else {var data = ""}
$("#x_UnitPrice").val(data);
});

Result:
(1) ProductID = 1 , UnitPrice = something
(2) ProductID = (Please Select) , UnitPrice = something <--- expect: empty value

The problem with (2) is this:
When I choose (Please Select) ew_Ajax will run "SELECT UnitPrice FROM products WHERE ProductID = null"
which is WRONG query.

I solved my case by changing ProductID datatype to string and change {query_value} to '{query_value}'. Keep ProductID as integer will not work because query "ProductID = " will work only for non-null value. If you want to keep it as integer then you have to write conditional ew_SetClientVar.


sangnandar
User
Posts: 980

Post by sangnandar »

A little more.

Don't use strict === operator when checking empty result from db.

var result = ew_Ajax(bla..bla..bla..)
if (result === "") {$label_value = "" ;} <--- will not working since empty set from db is an array, not a string.

Use == operator instead.
Or use (!result.length) <--- array of no-length (empty array).


Post Reply