import * as Survey from "survey-knockout" ; import { SurveyPropertyEditorBase } from "./propertyEditorBase" ; export class SurveyPropertyCustomEditor extends SurveyPropertyEditorBase { private widgetJSONValue : any ; public onValueChangedCallback : ( newValue : any ) => void ; constructor ( property , widgetJSON = null ) { super ( property ) ; this . widgetJSONValue = widgetJSON ; var self = this ; this [ "koAfterRender" ] = function ( componentInfo ) { const el = componentInfo . element . nextSibling ; self . doAfterRender ( el ) ; } ; } public get editorType ( ) : string { return "custom" ; } public get widgetJSON ( ) : any { return this . widgetJSONValue ; } private isValueChanging : boolean = false ; protected onValueChanged ( ) { if ( this . isValueChanging ) return ; this . isValueChanging = true ; super . onValueChanged ( ) ; if ( this . onValueChangedCallback ) this . onValueChangedCallback ( this . koValue ( ) ) ; this . isValueChanging = false ; } protected checkForErrors ( ) { var res = super . checkForErrors ( ) ; if ( ! ! res ) return res ; var errorText = this . widgetValidate ( ) ; if ( ! ! errorText ) { this . koErrorText ( errorText ) ; } return ! ! errorText ; } protected get widgetRender ( ) : any { return this . widgetJSON ? this . widgetJSON . render : null ; } protected widgetValidate ( ) { if ( this . widgetJSON && this . widgetJSON . validate ) { return this . widgetJSON . validate ( this , this . koValue ( ) ) ; } return null ; } protected doAfterRender ( el ) { if ( ! ! el && this . widgetRender ) this . widgetRender ( this , el ) ; } }