Note that there are some explanatory texts on larger screens.

plurals
  1. POSencha Touch 2 : A simple handler for HTML Button displayed insided panel is giving undefined error
    primarykey
    data
    text
    <p>I have a pretty simple html. This html is displayed inside Sencha Panel using panel.setHtml method. LayOut of the sample HTML is as below.</p> <p><em><strong>HTML File</em></strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script&gt; function copyText() { alert('It is clicked'); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; Field1: &lt;input type="text" id="field1" value="Hello World!"&gt;&lt;br&gt; Field2: &lt;input type="text" id="field2"&gt; &lt;br&gt;&lt;br&gt; &lt;button onclick="copyText()"&gt;Copy Text&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Below code sets html inside the panel.The above mentioned html is truncated into one line and is set inside the panel as below.</p> <pre><code>var res = '&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;script&gt;function copyText(){}&lt;/script&gt;&lt;/head&gt;&lt;body&gt;Field1: &lt;input type="text" id="field1" value="Hello World!"&gt;&lt;br&gt;Field2: &lt;input type="text" id="field2"&gt;&lt;br&gt;&lt;br&gt;&lt;button onclick="copyText()"&gt;Copy Text&lt;/button&gt;&lt;p&gt;A function is triggered when the button is clicked. The function copies the text from Field1 into Field2.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'; Ext.getCmp('dummyPanel').setHtml(res); </code></pre> <p><strong>ISSUE :</strong></p> <p><strong>When the Button is clicked, I am getting 'Uncaught ReferenceError: copyText is not defined' Error.</strong></p> <p>Any ideas of what wrong I am doing here? Cant we set the complete html with the inside the sencha panel.</p> <p>The running code is at <strong><a href="http://www.senchafiddle.com/#5LdC5" rel="nofollow">http://www.senchafiddle.com/#5LdC5</a></strong></p> <p>Please help.</p> <p>Thank you, Gendaful</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COWhy are you putting a whole `html` document in a panel? I don't know that ST2 is smart enough to wrap that in an `iframe` (which would be necessary). You should try using an actual [button](http://docs.sencha.com/touch/2-1/#!/api/Ext.Button) with a handler similar to what @Sergio has in his answer.
      singulars
    2. COI am putting the whole HTML in the panel as I am gettting the whole html from the server as a response and I have to display it as it is.This HTML contains events handling and frontend validations as well. So, this is the reason I have dependent to display the whole HTML inside the panel. Completely agreed with you that I have to parse the server response HTML and create the sencha native components accordingly and write my own validations as the above approach does not seems to be working. Thanks for the pointers.
      singulars
    3. COI guess my only suggestion is to maybe wrap that html document in an `<iframe>` before you put it in using `Ext.getCmp('dummyPanel').setHtml(res)`. (You know, if you _don't_ parse the whole thing... and parsing it could be a beast.) Good luck.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload