I want to hide some fields based on user entered value in some another field. Is any way to get field value in Add Page confirmation page?
Hide fields in confirmation page
-
- User
- Posts: 5
I need to show a field called total on the confirmation page but this total is calculated from two fields from user input on the add page. The confirmation page only shows the two fields, not the total. Kindly assist on having the total calculated and displayed on the confirmation page
-
- User
- Posts: 642
If total intitially exeists on the form as well as the two fileds, they you can attach clent side events to the two filed to alwas calculat the total value and put it in total column when user changes them.
That way you can alwyas hie the total field using jquery on page load such that it still has a vlaue but its just not visible. AFter that during confirmation you can then inturn hide the two field and show the total filed instead.
You can event add it as a div somewhere during confirm page that way you wont need it to be an actual field.
The only challenging thing here id detrmining the page state via client side.
- lets always pass the page action from the server side to client side, go to page_render of edit page and put.
// Page Render event
function Page_Render() {
//echo "Page Render"; //confrim page is CurrentPage()->CurrentAction == "F" //send current action so its accesible on cline side ew_SetClientVar("current_action", CurrentPage()->CurrentAction); var_dump(CurrentPage()->CurrentAction);
}
Now that we have the current action we can check for it and do our own jquery hiding or whatever. This is avalibale all the time so you use it as you want. For example. go to client scripts->startup scripts and of edit page and put this.
//check if current action was passed
if(typeof ewVar.current_action != 'undefined'){
console.log(ewVar.current_action);
//check if its confirm page
if(ewVar.current_action == "F")
{
alert("we are on confrim page");
//hide a field. Inspect and see what you need
$("#r_first_name").hide();
}
else
{
{
alert("we are NOT on confrim page");
}
}
}else{
alert("You didnt pass the current action");
}
-
- User
- Posts: 5
Thanks, my other question is do you have example Client side code to calculate the total from multipiying two fields called Price and Qty the assign the result to a form field called total
-
- User
- Posts: 642
if the form field is also an actaul field on the form like the price and quantity, then you can attach onchange event to the price and quantity fields and in those events put code to calculate the toatal and put it in the total field.
You can check the orderdetails table in demo project for a real example but in a summary.
go to price filed->go to field settings->click on client side scripts->in thr popup ddialog type the following.
{ // keys = event types, values = handler functions
"keyup change": function(e) {
//get all fields on the form
var $row = $(this).fields();
//calculate the total value
var item_total = $row["quantity"].toNumber() * $row["price"].toNumber();
//assign to total field
$row["sub_total"].value(amount_with_vat);
}
}
go to the quantity field and do the same.
NOTE: ensure the filed names are the right ones for your structure
After that now your total will automatically be calculated everytime the price or quantity cahnges on the form, ASSUMIN the total filed is only hidden it will still hold the most recent total so you wont have to recalculate it yourself at the tiem of showing it.
BUT if you want to calculate it only when you show the total field then you dont even need to have the total filed as an actual field o the form, you can use jquery for that.