Custom Validation


Hello All

1 I have added custom field(destination_warehouse) in Warehouse doctype.
2 I have created custom script for stock entry
3  At the time of creating stock entry, i have select default source warehouse
4 In custom script, i used return query on Default Target Warehouse which retrieve destination warehouse whose name i have taken in default source warehouse.
5 I have added custom_validate function for validation in stock entries custom script
6 I used wn.call method to verify source and destination warehouse which i am validating selected warehouses
7 if relation between source and destination warehouse is incorrect then it alert (You have selected invalid warehouse. Please, reselect.)
8 At the end of wn.call i have set flag=‘false’
9 Then i alert(“checking”) after wn.call
10 After checking alert i checked whether flag is true or false
11 if flag is false then validated=false (do not save form)

Problem:
1 All above is working fine except validated = false
2 On Firefox i have seen that
  case a) if i used alert(“checking”) then validated=false is work.
  case b) if i remove alert(“checking”) then it did not work
4 On chrome, validated = false is not working for any cases.
5 So my problem is if flag is false, then data should not be save
6 In my cases it saved the data

For your reference i have pasted my code at http://pastebin.com/c3xjLNvL

Thanks and Regards
Rohit



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.

     

     
Rohit,

Thanks for clearer explanation :)

Validation will not work in asynchronous calls - this is basic stuff. The JS engine does not wait for call to be completed. You will have to validate this on server side. There is no other system right now.

There is another hack - you can use a synchronous call instead of wn.call (or extend wn.call to accept synchronous calls).

- Rushabh


T: @rushabh_mehta

On 24-Jul-2013, at 3:53 PM, Rohit Waghchaure <ro...@indictranstech.com> wrote:


Hello All

1 I have added custom field(destination_warehouse) in Warehouse doctype.
2 I have created custom script for stock entry
3  At the time of creating stock entry, i have select default source warehouse
4 In custom script, i used return query on Default Target Warehouse which retrieve destination warehouse whose name i have taken in default source warehouse.
5 I have added custom_validate function for validation in stock entries custom script
6 I used wn.call method to verify source and destination warehouse which i am validating selected warehouses
7 if relation between source and destination warehouse is incorrect then it alert (You have selected invalid warehouse. Please, reselect.)
8 At the end of wn.call i have set flag='false'
9 Then i alert("checking") after wn.call
10 After checking alert i checked whether flag is true or false
11 if flag is false then validated=false (do not save form)

Problem:
1 All above is working fine except validated = false
2 On Firefox i have seen that
  case a) if i used alert("checking") then validated=false is work.
  case b) if i remove alert("checking") then it did not work
4 On chrome, validated = false is not working for any cases.
5 So my problem is if flag is false, then data should not be save
6 In my cases it saved the data

For your reference i have pasted my code at http://pastebin.com/c3xjLNvL

Thanks and Regards
Rohit




Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.

     

     



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.