Error on raddataform validator

telerikuicomponent

#1

I wanna make minimum length validator on year input. so i follow example on https://www.nativescript.org/blog/a-deep-dive-into-telerik-ui-for-nativescripts-dataform and when my input hits null it got error. and it happen on maximum length validator. when i fill a lot of number it hits error too. it there any simple example of using raddataform. Thanks for kinda help…

here is code
main-page.xml

<Page xmlns:df="nativescript-pro-ui/dataform" xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded">
    <ActionBar title="RadDataForm Demo" class="action-bar" />
    <df:RadDataForm id="myDataForm" source="{{ album }}">
		<df:RadDataForm.properties>
			<df:EntityProperty name="albumName" displayName="Name of Album" index="0" />
			<df:EntityProperty name="bandName"  hint="xxxx" displayName="Name of Band" index="1" >
				<df:EntityProperty.validators>
					<df:MinimumLengthValidator errorMessage="Year must be at least 4 digits!" length="4" />
				</df:EntityProperty.validators>
			</df:EntityProperty>
			<df:EntityProperty name="year" displayName="Release Tahun" index="2">
				<df:EntityProperty.editor>
					<df:PropertyEditor type="Number" />
				</df:EntityProperty.editor>
				<df:EntityProperty.validators>
					<df:MinimumLengthValidator errorMessage="Year must be at least 4 digits!" length="4" />
				</df:EntityProperty.validators>
			</df:EntityProperty>
			<df:EntityProperty name="myRating" displayName="Ratingnya" index="3" >
				<df:EntityProperty.editor>
					<df:PropertyEditor type="Slider" >
						<df:PropertyEditor.params>
							<df:PropertyEditorParams minimum="0" maximum="10" />
						</df:PropertyEditor.params>
					</df:PropertyEditor>
				</df:EntityProperty.editor>
			</df:EntityProperty>
			<df:EntityProperty name="owned" displayName="Do I Own This??" index="4" />
			<df:EntityProperty name="gender" displayName="Gender" valuesProvider="Male, Female, Other">
				<df:EntityProperty.editor>
					<df:PropertyEditor type="SegmentedEditor" />
				</df:EntityProperty.editor>
			</df:EntityProperty>
		</df:RadDataForm.properties>
	</df:RadDataForm>
</Page>

main-page.js

var Observable = require("data/observable").Observable;

var page;
var album = new Observable();
var pageData = new Observable();

exports.pageLoaded = function(args) {
    page = args.object;
    page.bindingContext = pageData;

    album = {
        bandName: "Arcade Fire",
        albumName: "Funeral",
        year: 2004,
        myRating: 2,
		gender : 'Male'
    };

    pageData.set("album", album);
};



#2

Hi, you should have to change your code. MinimumLengthValidator only works with String not Number

                    <df:EntityProperty name="year" displayName="Release" index="2">
                        <df:EntityProperty.editor>
                            <df:PropertyEditor type="Number" />
                        </df:EntityProperty.editor>
                        <df:EntityProperty.validators>
                            <df:RegExValidator regEx="\d{4}" errorMessage="Year must be 4 digits!"/>
                        </df:EntityProperty.validators>
                    </df:EntityProperty>

#3

still wont work. i got this error

An uncaught Exception occurred on “main” thread.
java.lang.NullPointerException
at com.telerik.widget.dataform.engine.MinimumLengthValidator.validateCore(MinimumLengthValidator.java:23)
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.onEditorValueChanged(EntityPropertyEditor.java:270)
at com.telerik.widget.dataform.visualization.editors.DataFormIntegerEditor.onTextChanged(DataFormIntegerEditor.java:101)
at android.widget.TextView.sendOnTextChanged(TextView.java:7408)
at android.widget.TextView.handleTextChanged(TextView.java:7467)
at android.widget.TextView$ChangeWatcher.onTextChanged(TextV


#4

Hi, MinimumLengthValidator only woks with Strings, not numbers. If you want to use MinimumLengthValidator you have to change your code to:

album = {
        bandName: "Arcade Fire",
        albumName: "Funeral",
        year: "2004",
        owned: true,
        myRating: "9.5"
    };
<df:EntityProperty name="year" displayName="Release Tahun" index="2">
	<df:EntityProperty.validators>
		<df:MinimumLengthValidator errorMessage="Year must be at least 4 digits!" length="4" />
	</df:EntityProperty.validators>
</df:EntityProperty>

#5

if i put number for keyboard type all xml will be invisible im using same example of yours