Client side scripting help

hello,

i am writing the custom client side scripting , earlier i thought that i could use the jquery.

but this isnt the case.

i am trying to add a field called “HOME NUMBER”… field name : “home_number”

the user must enter the home number , if he selects the another field which is checkbox called , “i have a home number”. field_name : “select_home”

cur_frm.cscript.select_home = function(doc, cdt, cdn) {

if(doc.select_home == 1)
   {

 

      doc.home_number.style.display = “block”;
 

}
else
{
   doc.home_number.style.display = “none”;
}
    refresh_field(‘home_number’);
}

cur_frm.cscript.select_home; // i just tried to run this trigger but i dont know how to run this trigger from here…

i tried something like this as well

$(‘input[name=“home_number”]’).val(); // this returns me undefined , whereas if i go and execute this on console i get the value for this same command.




any help with this guys.



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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/Zf80HxSK3dkJ.

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

 

 

Please use gist or pastebin to share code snippets. Its not readable otherwise.


On Wed, Mar 6, 2013 at 12:15 PM, Syed Qadeer <sd...@gmail.com> wrote:
hello,

i am writing the custom client side scripting , earlier i thought that i could use the jquery.

but this isnt the case.

i am trying to add a field called "HOME NUMBER".... field name : "home_number"

the user must enter the home number , if he selects the another field which is checkbox called , "i have a home number". field_name : "select_home"

cur_frm.cscript.select_home = function(doc, cdt, cdn) {

if(doc.select_home == 1)
{



doc.home_number.style.display = "block";


}
else
{
doc.home_number.style.display = "none";
}
refresh_field('home_number');
}

cur_frm.cscript.select_home; // i just tried to run this trigger but i dont know how to run this trigger from here....

i tried something like this as well

$('input[name="home_number"]').val(); // this returns me undefined , whereas if i go and execute this on console i get the value for this same command.




any help with this guys.



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.

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/Zf80HxSK3dkJ.

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














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.

To post to this group, send email to er...@googlegroups.com.

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

 

 

hi rusabh,

please find the below link

gist:5097290 · GitHub


On Wednesday, 6 March 2013 09:47:53 UTC+3, rushabh wrote:

Please use gist or pastebin to share code snippets. Its not readable otherwise.


On Wed, Mar 6, 2013 at 12:15 PM, Syed Qadeer <sd…@gmail.com> wrote:

hello,

i am writing the custom client side scripting , earlier i thought that i could use the jquery.

but this isnt the case.

i am trying to add a field called "HOME NUMBER".... field name : "home_number"

the user must enter the home number , if he selects the another field which is checkbox called , "i have a home number". field_name : "select_home"

cur_frm.cscript.select_home = function(doc, cdt, cdn) {

if(doc.select_home == 1)
   {

 

      doc.home_number.style.display = "block";
 

}
else
{
   doc.home_number.style.display = "none";
}
    refresh_field('home_number');
}

cur_frm.cscript.select_home; // i just tried to run this trigger but i dont know how to run this trigger from here....

i tried something like this as well

$('input[name="home_number"]').val(); // this returns me undefined , whereas if i go and execute this on console i get the value for this same command.




any help with this guys.



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.

To post to this group, send email to erpnext-dev…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/Zf80HxSK3dkJ.

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

 

 










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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/BtZTzmzsz7UJ.

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

 

 

Hi,

This script is executed before the form is loaded so you have to write all functions in a trigger.

Please see examples here for how to achieve this:

https://github.com/webnotes/wnframework/wiki/Client-side-scripting

(for a sample see "Make Attachments Mandatory") -- you can use a similar function to make selective mandatory.

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

On 06-Mar-2013, at 12:28 PM, Syed Qadeer <sd...@gmail.com> wrote:

hi rusabh,

please find the below link

https://gist.github.com/anonymous/5097290


On Wednesday, 6 March 2013 09:47:53 UTC+3, rushabh wrote:
Please use gist or pastebin to share code snippets. Its not readable otherwise.


On Wed, Mar 6, 2013 at 12:15 PM, Syed Qadeer <sd...@gmail.com> wrote:
hello,

i am writing the custom client side scripting , earlier i thought that i could use the jquery.

but this isnt the case.

i am trying to add a field called "HOME NUMBER".... field name : "home_number"

the user must enter the home number , if he selects the another field which is checkbox called , "i have a home number". field_name : "select_home"

cur_frm.cscript.select_home = function(doc, cdt, cdn) {

if(doc.select_home == 1)
   {

 

      doc.home_number.style.display = "block";
 

}
else
{
   doc.home_number.style.display = "none";
}
    refresh_field('home_number');
}

cur_frm.cscript.select_home; // i just tried to run this trigger but i dont know how to run this trigger from here....

i tried something like this as well

$('input[name="home_number"]').val(); // this returns me undefined , whereas if i go and execute this on console i get the value for this same command.




any help with this guys.



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.

To post to this group, send email to erpnext-dev…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/Zf80HxSK3dkJ.

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

 

 











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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/BtZTzmzsz7UJ.

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

 

 




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.

To post to this group, send email to er...@googlegroups.com.

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

 

 

let me put it this way … if i want to hide an element during the page/form load based upon the value in the textbox??

how can i do that ??

On Wednesday, 6 March 2013 10:04:58 UTC+3, rushabh wrote:

Hi,

This script is executed before the form is loaded so you have to write all functions in a trigger.

Please see examples here for how to achieve this:


(for a sample see “Make Attachments Mandatory”) – you can use a similar function to make selective mandatory.

best,
Rushabh



W: https://erpnext.com
T: @rushabh_mehta

On 06-Mar-2013, at 12:28 PM, Syed Qadeer <sd...@gmail.com> wrote:

hi rusabh,

please find the below link

https://gist.github.com/anonymous/5097290


On Wednesday, 6 March 2013 09:47:53 UTC+3, rushabh wrote:
Please use gist or pastebin to share code snippets. Its not readable otherwise.


On Wed, Mar 6, 2013 at 12:15 PM, Syed Qadeer <sd...@gmail.com> wrote:
hello,

i am writing the custom client side scripting , earlier i thought that i could use the jquery.

but this isnt the case.

i am trying to add a field called "HOME NUMBER".... field name : "home_number"

the user must enter the home number , if he selects the another field which is checkbox called , "i have a home number". field_name : "select_home"

cur_frm.cscript.select_home = function(doc, cdt, cdn) {

if(doc.select_home == 1)
   {

 

      doc.home_number.style.display = "block";
 

}
else
{
   doc.home_number.style.display = "none";
}
    refresh_field('home_number');
}

cur_frm.cscript.select_home; // i just tried to run this trigger but i dont know how to run this trigger from here....

i tried something like this as well

$('input[name="home_number"]').val(); // this returns me undefined , whereas if i go and execute this on console i get the value for this same command.




any help with this guys.



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.

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/Zf80HxSK3dkJ.

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

 

 











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.

To post to this group, send email to erpnext-dev…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/BtZTzmzsz7UJ.

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

 

 




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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/w65VMCfeDhoJ.

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

 

 

Declare a function in cur_frm.cscript.custom_refresh and add you code there.


On 06-Mar-2013, at 1:07 PM, Syed Qadeer <sd...@gmail.com> wrote:

let me put it this way ... if i want to hide an element during the page/form load based upon the value in the textbox??

how can i do that ??

On Wednesday, 6 March 2013 10:04:58 UTC+3, rushabh wrote:
Hi,

This script is executed before the form is loaded so you have to write all functions in a trigger.

Please see examples here for how to achieve this:


(for a sample see "Make Attachments Mandatory") -- you can use a similar function to make selective mandatory.

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

On 06-Mar-2013, at 12:28 PM, Syed Qadeer <sd...@gmail.com> wrote:

hi rusabh,

please find the below link

https://gist.github.com/anonymous/5097290


On Wednesday, 6 March 2013 09:47:53 UTC+3, rushabh wrote:
Please use gist or pastebin to share code snippets. Its not readable otherwise.


On Wed, Mar 6, 2013 at 12:15 PM, Syed Qadeer <sd...@gmail.com> wrote:
hello,

i am writing the custom client side scripting , earlier i thought that i could use the jquery.

but this isnt the case.

i am trying to add a field called "HOME NUMBER".... field name : "home_number"

the user must enter the home number , if he selects the another field which is checkbox called , "i have a home number". field_name : "select_home"

cur_frm.cscript.select_home = function(doc, cdt, cdn) {

if(doc.select_home == 1)
   {

 

      doc.home_number.style.display = "block";
 

}
else
{
   doc.home_number.style.display = "none";
}
    refresh_field('home_number');
}

cur_frm.cscript.select_home; // i just tried to run this trigger but i dont know how to run this trigger from here....

i tried something like this as well

$('input[name="home_number"]').val(); // this returns me undefined , whereas if i go and execute this on console i get the value for this same command.




any help with this guys.



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.

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/Zf80HxSK3dkJ.

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

 

 











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.

To post to this group, send email to erpnext-dev…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/BtZTzmzsz7UJ.

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

 

 





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.

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/w65VMCfeDhoJ.

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

 

 




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.

To post to this group, send email to er...@googlegroups.com.

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

 

 

just need 1 more help over here …

i am trying to run a condition during the save for the Employee.

gist:5098651 · GitHub

and i am calling the “cur_frm.cscript.on_submit = function(doc)

but this is not getting executed…



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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OJNcmCidLiUJ.

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

 

 

Use "custom_on_submit" instead of "on_submit"

Regards,
Nabin Hait

On 06-Mar-2013, at 4:49 PM, Syed Qadeer wrote:

just need 1 more help over here ...

i am trying to run a condition during the save for the Employee.

https://gist.github.com/anonymous/5098651

and i am calling the "cur_frm.cscript.on_submit = function(doc)"

but this is not getting executed....



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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OJNcmCidLiUJ.

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

 

 




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.

To post to this group, send email to er...@googlegroups.com.

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

 

 

this is still not working … i am not getting the alertbox…

On Wednesday, 6 March 2013 14:21:34 UTC+3, Nabin Hait wrote:

Use “custom_on_submit” instead of “on_submit”


Regards,
Nabin Hait


On 06-Mar-2013, at 4:49 PM, Syed Qadeer wrote:

just need 1 more help over here ...

i am trying to run a condition during the save for the Employee.

https://gist.github.com/anonymous/5098651

and i am calling the "cur_frm.cscript.on_submit = function(doc)"

but this is not getting executed....



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.

To post to this group, send email to erpnext-dev…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OJNcmCidLiUJ.

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

 

 




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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/LFeC4Y7w-JMJ.

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

 

 

There could be a syntax Error.

Also on_submit is not called while saving, you have to use custom_validate function to write your event.

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

On 06-Mar-2013, at 5:21 PM, Syed Qadeer <sd...@gmail.com> wrote:

this is still not working ... i am not getting the alertbox...

On Wednesday, 6 March 2013 14:21:34 UTC+3, Nabin Hait wrote:
Use "custom_on_submit" instead of "on_submit"

Regards,
Nabin Hait

On 06-Mar-2013, at 4:49 PM, Syed Qadeer wrote:

just need 1 more help over here ...

i am trying to run a condition during the save for the Employee.

https://gist.github.com/anonymous/5098651

and i am calling the "cur_frm.cscript.on_submit = function(doc)"

but this is not getting executed....



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.

To post to this group, send email to erpnext-dev…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OJNcmCidLiUJ.

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

 

 





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.

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/LFeC4Y7w-JMJ.

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

 

 




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.

To post to this group, send email to er...@googlegroups.com.

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

 

 

hey rusabh, thanks for that … it is working however, if you see the above code … i am returning false if the condition fails, but even though i am returning false… the data is getting saved in the database. it is not coming out of that ??

On Wednesday, 6 March 2013 14:53:18 UTC+3, rushabh wrote:

There could be a syntax Error.

Also on_submit is not called while saving, you have to use custom_validate function to write your event.

best,
Rushabh



W: https://erpnext.com
T: @rushabh_mehta

On 06-Mar-2013, at 5:21 PM, Syed Qadeer <sd...@gmail.com> wrote:

this is still not working ... i am not getting the alertbox...

On Wednesday, 6 March 2013 14:21:34 UTC+3, Nabin Hait wrote:
Use "custom_on_submit" instead of "on_submit"

Regards,
Nabin Hait

On 06-Mar-2013, at 4:49 PM, Syed Qadeer wrote:

just need 1 more help over here ...

i am trying to run a condition during the save for the Employee.

https://gist.github.com/anonymous/5098651

and i am calling the "cur_frm.cscript.on_submit = function(doc)"

but this is not getting executed....



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.

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OJNcmCidLiUJ.

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

 

 





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.

To post to this group, send email to erpnext-dev…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/LFeC4Y7w-JMJ.

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

 

 




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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/6GhJZo5LAOYJ.

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

 

 

got it working,… thanks…

and rusabh i now understand what you meant by “Make attachments mandatory:”


On Wednesday, 6 March 2013 15:02:18 UTC+3, Syed Qadeer wrote:

hey rusabh, thanks for that … it is working however, if you see the above code … i am returning false if the condition fails, but even though i am returning false… the data is getting saved in the database. it is not coming out of that ??

On Wednesday, 6 March 2013 14:53:18 UTC+3, rushabh wrote:
There could be a syntax Error.

Also on_submit is not called while saving, you have to use custom_validate function to write your event.

best,
Rushabh



W: https://erpnext.com
T: @rushabh_mehta

On 06-Mar-2013, at 5:21 PM, Syed Qadeer <sd...@gmail.com> wrote:

this is still not working ... i am not getting the alertbox...

On Wednesday, 6 March 2013 14:21:34 UTC+3, Nabin Hait wrote:
Use "custom_on_submit" instead of "on_submit"

Regards,
Nabin Hait

On 06-Mar-2013, at 4:49 PM, Syed Qadeer wrote:

just need 1 more help over here ...

i am trying to run a condition during the save for the Employee.

https://gist.github.com/anonymous/5098651

and i am calling the "cur_frm.cscript.on_submit = function(doc)"

but this is not getting executed....



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.

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OJNcmCidLiUJ.

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

 

 





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.

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/LFeC4Y7w-JMJ.

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

 

 




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.

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/rBm2WsiGX7UJ.

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