@@ -59,20 +59,23 @@ function init(Survey) {
5959 afterRender : function ( question , el ) {
6060 var rootWidget = this ;
6161 var canvas = el . getElementsByTagName ( "canvas" ) [ 0 ] ;
62+ var buttonEl = el . getElementsByTagName ( "button" ) [ 0 ] ;
6263 var signaturePad = new SignaturePad ( canvas ) ;
6364 if ( question . isReadOnly ) {
6465 signaturePad . off ( ) ;
6566 }
6667
68+ buttonEl . onclick = function ( ) {
69+ question . value = undefined ;
70+ } ;
71+
6772 question . readOnlyChangedCallback = function ( ) {
68- if ( question . isReadOnly ) {
73+ if ( ! question . allowClear || question . isReadOnly ) {
6974 signaturePad . off ( ) ;
70- var clearBtn = document . querySelector ( ".sjs_sp_clear" ) ;
71- clearBtn && ( clearBtn . disabled = true ) ;
75+ buttonEl . style . display = "none" ;
7276 } else {
7377 signaturePad . on ( ) ;
74- var clearBtn = document . querySelector ( ".sjs_sp_clear" ) ;
75- clearBtn && ( clearBtn . disabled = false ) ;
78+ buttonEl . style . display = "block" ;
7679 }
7780 } ;
7881
@@ -92,6 +95,7 @@ function init(Survey) {
9295 } ;
9396 question . valueChangedCallback = updateValueHandler ;
9497 updateValueHandler ( ) ;
98+ question . readOnlyChangedCallback ( ) ;
9599 question . signaturePad = signaturePad ;
96100 var propertyChangedHandler = function ( sender , options ) {
97101 if ( options . name === "width" || options . name === "height" ) {
@@ -100,14 +104,6 @@ function init(Survey) {
100104 } ;
101105 question . onPropertyChanged . add ( propertyChangedHandler ) ;
102106 question . signaturePad . propertyChangedHandler = propertyChangedHandler ;
103- var buttonEl = el . getElementsByTagName ( "button" ) [ 0 ] ;
104- if ( question . allowClear && ! question . isReadOnly ) {
105- buttonEl . onclick = function ( ) {
106- question . value = undefined ;
107- } ;
108- } else {
109- buttonEl . parentNode . removeChild ( buttonEl ) ;
110- }
111107 } ,
112108 willUnmount : function ( question , el ) {
113109 if ( question . signaturePad ) {
0 commit comments