[ 
https://issues.apache.org/jira/browse/WICKET-4199?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ernesto Reinaldo Barreiro updated WICKET-4199:
----------------------------------------------

    Attachment: SubmitLink.java.patch

patch that adds method to class
                
> add a hook to  SubmitLink  that allows to insert arbitrary JavaScript before 
> code that submit the form
> ------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-4199
>                 URL: https://issues.apache.org/jira/browse/WICKET-4199
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.5.2
>            Reporter: Ernesto Reinaldo Barreiro
>            Priority: Minor
>              Labels: wicket
>         Attachments: SubmitLink.java.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> I need to execute some JavaScript before form is submmited and as method 
> getTriggerJavaScrip is final I have to  do it like
> SubmitLink link = new SubmitLink("link") {
>                       
>                       private static final long serialVersionUID = 1L;
>                       
>                       @Override
>                       protected void onComponentTag(ComponentTag tag)
>                       {
>                               super.onComponentTag(tag);
>                               // If we're disabled
>                               if (!isLinkEnabled())
>                               {
>                                       disableLink(tag);
>                               }
>                               else
>                               {
>                                       if (tag.getName().equalsIgnoreCase("a"))
>                                       {
>                                               tag.put("href", "#");
>                                       }
>                                       tag.put("onclick", 
> getTriggerJavaScript1());
>                               }
>                       }
>                       
>                       protected  String getTriggerJavaScript1()
>                       {
>                               if (getForm() != null)
>                               {
>                                       // find the root form - the one we are 
> really going to submit
>                                       Form<?> root = getForm().getRootForm();
>                                       StringBuilder sb = new 
> StringBuilder(100);
>                                       // my code
>                                       sb.append("document.getElementById('");
>                                       sb.append(description.getMarkupId());
>                                       
> sb.append("').value=CKEDITOR.instances.");
>                                       sb.append(description.getMarkupId());
>                                       sb.append(".getData();");
>                                       // end of my code 
>                                       sb.append("var 
> e=document.getElementById('");
>                                       sb.append(root.getHiddenFieldId());
>                                       sb.append("'); e.name=\'");
>                                       sb.append(getInputName());
>                                       sb.append("'; e.value='x';");
>                                       sb.append("var 
> f=document.getElementById('");
>                                       sb.append(root.getMarkupId());
>                                       sb.append("');");                       
>                 
>                                       if 
> (shouldInvokeJavaScriptFormOnsubmit())
>                                       {
>                                               if (getForm() != root)
>                                               {
>                                                       sb.append("var 
> ff=document.getElementById('");
>                                                       
> sb.append(getForm().getMarkupId());
>                                                       sb.append("');");
>                                               }
>                                               else
>                                               {
>                                                       sb.append("var ff=f;");
>                                               }
>                                               sb.append("if (ff.onsubmit != 
> undefined) { if (ff.onsubmit()==false) return false; }");
>                                       }
>                                       
> sb.append("f.submit();e.value='';e.name='';return false;");
>                                       return sb.toString();
>                               }
>                               else
>                               {
>                                       return null;
>                               }
>                       }
>               }; 
> This ugly and moreover if form submiting logic changes my extended link might 
> stop to work properly. I propose adding a method  decorareTriggerJavaScript 
> that allows users to decorate the form submiting script. e.g. in my case
> SubmitLink link = new SubmitLink("link") {
>                       private static final long serialVersionUID = 1L;
>                       
>                       @Override
>                       protected void decorareTriggerJavaScript(StringBuilder 
> sb) {
>                               StringBuilder sb1 = new StringBuilder(100);
>                               sb1.append("document.getElementById('");
>                               sb1.append(description.getMarkupId());
>                               sb1.append("').value=CKEDITOR.instances.");
>                               sb1.append(description.getMarkupId());
>                               sb1.append(".getData();");                      
>                               sb.insert(0, sb1.toString());
>                       }
>               };

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to