Skip to content

Commit

Permalink
Merge pull request #14 from hanhsu/B70-CKEZ-13
Browse files Browse the repository at this point in the history
Fix Issue #13: unexpected onChange event after setting the value (with B...
  • Loading branch information
hanhsu committed Nov 14, 2014
2 parents c29ae27 + 9f7f44d commit 4cfaa0e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
11 changes: 9 additions & 2 deletions ckez/src/archive/web/js/ckez/CKeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ckez.CKeditor = zk.$extends(zul.Widget, {
var editor = this.getEditor();
if (editor) {
editor.setData(v);
// Issue #9 refix: update editor's previousValue if set value from server
// Issue #9: update editor's previousValue if set value from server
// to prevent unexpect onChange event
if (fromServer)
editor._.previousValue = editor.dataProcessor.toHtml(v);
Expand Down Expand Up @@ -393,7 +393,7 @@ ckez.CKeditor = zk.$extends(zul.Widget, {
wgt._tidChg = null;
}

if (editor.checkDirty()) {
if (wgt.$class._checkEditorDirty(editor)) { // Issue #13
var val = editor.getData();
wgt._value = val; //save for onRestore
// B70-CKEZ-23: Do not send ahead when fire onChange, it will reverse the queue.
Expand Down Expand Up @@ -457,5 +457,12 @@ ckez.CKeditor = zk.$extends(zul.Widget, {
textArea.height(h);
},20);
}
},

// Issue #13: pass through the html formatter before compare
_checkEditorDirty: function (editor) {
var fmtSnapshot = editor.dataProcessor.toHtml(editor.getSnapshot());
var fmtPreviousVal = editor.dataProcessor.toHtml(editor._.previousValue);
return editor.status == 'ready' && fmtPreviousVal !== fmtSnapshot;
}
});
34 changes: 34 additions & 0 deletions test/addon/ckeztest/src/archive/test2/B70-CKEZ-13.zul
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<zk>
<zscript><![CDATA[
String myValue = "<br><p>line1<br/>\nline</p>";
public updateMyValue(String newValue) {
myValue = newValue;
editor.setValue(myValue);
//Clients.showNotification("updated myValue to: " + myValue);
}
]]></zscript>
<vlayout>
<button label="1. update editor value to empty" onClick='updateMyValue("");'/>
<button label="2. update editor value to 'XYZ'" onClick='updateMyValue("XYZ");'/>
<button label="3. do something unrelated and show 'myvalue'" onClick='debugLabel.setValue("myValue: " + myValue);'/>
<label id="debugLabel"/>
<ckeditor id="editor" value="${myValue}" onChange="myValue = self.getValue();"/>
</vlayout>
<!-- <vlayout> -->
<!-- <button -->
<!-- label="1. update editor value to '&lt;p&gt;line1&lt;br/&gt;\nline2&lt;/p&gt;'" -->
<!-- onClick='updateMyValue("&lt;p&gt;line1&lt;br/&gt;\nline2&lt;/p&gt;");' /> -->
<!-- <button label="2. update editor value to 'XYZ'" onClick='updateMyValue("&lt;p&gt;XYZ&lt;/p&gt;");' /> -->
<!-- <button label="3. do something unrelated and show 'myvalue'" -->
<!-- onClick='debugLabel.setValue("myValue: " + myValue);' /> -->
<!-- <label id="debugLabel" /> -->
<!-- <ckeditor id="editor" value="${myValue}" onChange='myValue = self.getValue(); Clients.showNotification("onChanged");' /> -->
<!-- </vlayout> -->
<!-- <vlayout> -->
<!-- <label value="1. edit the text below" /> -->
<!-- <button label="2. update editor value to 'XYZ'" onClick='updateMyValue("&lt;p&gt;XYZ&lt;/p&gt;");'/> -->
<!-- <button label="3. do something unrelated and show 'myvalue'" onClick='debugLabel.setValue("myValue: " + myValue);'/> -->
<!-- <label id="debugLabel"/> -->
<!-- <ckeditor id="editor" value="${myValue}" onChange='myValue = self.getValue();'/> -->
<!-- </vlayout> -->
</zk>
3 changes: 2 additions & 1 deletion test/addon/ckeztest/src/archive/test2/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ B70-CKEZ-23.zul=Ckeditor,onChange
B70-CKEZ-22.zul=Ckeditor,FileUpload
B70-CKEZ-5.zul=Ckeditor,onSize
B70-CKEZ-7.zul=A,E,Ckeditor,onChanging,FireEvent
B70-CKEZ-9.zul=A,E,Ckeditor,onChange,setValue
B70-CKEZ-9.zul=A,E,Ckeditor,onChange,setValue
B70-CKEZ-13.zul=A,H,Ckeditor,onChange,fromServer,htmlFormat
1 change: 1 addition & 0 deletions zkdoc/ckez-release-note
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ckez 4.3.3.1
Issue #5: textarea of zkeditor not resizing properly
Issue #7: onChanging event not fired since ZK CKEditor 4.x
Issue #9: unexpected onChange event after setting the value from the server
Issue #13: unexpected onChange event after setting the value (with BR) from the server

* Upgrade Notes:

Expand Down

0 comments on commit 4cfaa0e

Please sign in to comment.