Numeric Validation in RadDataForm with extention of PropertyValidator gives Stacktrace


#1

Hi,
I’m trying to get a Numeric property validation to work, but get a Stacktrace:

An uncaught Exception occurred on “main” thread.
java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean com.telerik.widget.dataform.engine.PropertyValidatorBase.validateCore(java.lang.Object, java.lang.String)’ on a null object reference
at com.telerik.widget.dataform.engine.PropertyValidatorSet.validateCore(PropertyValidatorSet.java:31)
at com.telerik.widget.dataform.engine.PropertyValidatorBase.validate(PropertyValidatorBase.java:12)
at com.telerik.widget.dataform.engine.EntityPropertyCore.validate(EntityPropertyCore.java:558)
at com.telerik.widget.dataform.engine.EntityPropertyCore.tryCommit(EntityPropertyCore.java:417)
at com.telerik.widget.dataform.visualization.core.EntityPropertyEditor.onEditorLostFocus(EntityPropertyEditor.java:259)
at com.telerik.widget.dataform.visualization.editors.DataFormIntegerEditor.onFocusChange(DataFormIntegerEditor.java:170)
at android.view.View.onFocusChanged(View.java:5717)
at android.widget.TextView.onFocusChanged(TextView.java:8227)
at android.view.View.clearFocusInternal(View.java:5599)
at android.view.View.unFocus(View.java:5632)
at android.view.ViewGroup.unFocus(ViewGroup.java:996)
at android.view.ViewGroup.unFocus(ViewGroup.java:996)
at android.view.ViewGroup.unFocus(ViewGroup.java:996)
at android.view.ViewGroup.unFocus(ViewGroup.java:996)
at android.view.ViewGroup.unFocus(ViewGroup.java:996)
at android.view.ViewGroup.unFocus(ViewGroup.java:996)
at android.view.ViewGroup.unFocus(ViewGroup.java:996)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:734)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:740)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:740)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:740)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:740)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:740)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:740)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:740)
at android.view.View.handleFocusGainInternal(View.java:5465)
at android.view.View.requestFocusNoSearch(View.java:8470)
at android.view.View.requestFocus(View.java:8449)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4203)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4089)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3820)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3981)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2253)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1874)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1865)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2230)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

It’s a simple validator:

var NumValidator = (function (_super) {
__extends(NumValidator, _super);
function NumValidator() {
var _this = _super.call(this) || this;
_this.errorMessage = “Between 10 and 99”;
return _this;
}
NumValidator.prototype.validate = function (value, propertyName) {
return value >= 10 && value <=99;
};
}(dataFormModule.PropertyValidator));
exports.NumValidator = NumValidator;

and here is the xml:


<Page.actionBar>


</Page.actionBar>

<StackLayout class="p-20" orientation="vertical">
    <df:RadDataForm source="{{ person }}" commitMode="OnLostFocus" validationMode="OnLostFocus" >
        <df:RadDataForm.groups>
        <df:PropertyGroup collapsible="false" name="" hidden="false">
        <df:PropertyGroup.properties>
        <df:EntityProperty name="name" displayName="Full Name" >
            <df:EntityProperty.editor>
                <df:PropertyEditor type="Text"/>
            </df:EntityProperty.editor>
        </df:EntityProperty>

        <df:EntityProperty name="age" displayName="Age in Years">
            <df:EntityProperty.validators>
                <v:NumValidator />
            </df:EntityProperty.validators>
            <df:EntityProperty.editor>
                <df:PropertyEditor type="Number"/>
            </df:EntityProperty.editor>
        </df:EntityProperty>
        </df:PropertyGroup.properties>
        </df:PropertyGroup>
        </df:RadDataForm.groups>
    </df:RadDataForm>

    <Button text="TAP" tap="onTap" class="btn btn-primary btn-active"/>

</StackLayout>

I have no clue, what is going wrong, as the validate function isn’t called.

Did I miss something? Or is a numeric validation not yet possible?

Thanks for helping.

Cheers
Ralph


#2

Hi @rkl_de

I’m not able to find a validator named NumValidtor anywhere in the docs
http://docs.telerik.com/devtools/nativescript-ui/Controls/NativeScript/DataForm/Validation/dataform-validation-list

Are you sure it is a valid validator type?


#3

Hi @multishiv19,

thanks for your reply. No, NumValidator is a simple extention of the PropertyValidator. The code is right above the xml.
I tried several extentions of the PropertyValidator, but couldn’t get any of them to work with a Numeric input type.
I need a validation after the input if the entered number is between two values.

Cheers

Ralph


#4

When I took the custom validator sample in Ts, from the docs, and compiled it to JS,
it looked something like this

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
exports.__esModule = true;
var ExactTextValidator = (function (_super) {
    __extends(ExactTextValidator, _super);
    function ExactTextValidator() {
        var _this = _super.call(this) || this;
        _this.errorMessage = "Please enter: admin1";
        return _this;
    }
    ExactTextValidator.prototype.validate = function (value, propertyName) {
        return value.toLowerCase() == "admin1";
    };
    return ExactTextValidator;
}(dataFormModule.PropertyValidator));
exports.ExactTextValidator = ExactTextValidator;

can you try adding the polyfill for __extends like in the above code?


#5

Hi @multishiv19,

thanks for your help. I found the answer after several hours looking on the code :slight_smile:. I forgot to return the NumValidator.
Now it works properly.

Thanks again for looking at it.

Cheers
Ralph