View Full Version : setting regExpValidator for TextInput in QMl is not working
HI,
I just want to set a hexadecimal validator for my TextInput field in the qml, but somehow it is not validating. Instead of regExpValidator if i use intValidator it works. but I need to have a hexadecimal validator. again if i use Inputmask , it works but I need to specify the no of characters which I cant becuase I need to have it as unlimited.
here is the code sample:
TextInput{
id:display
text:some value from cpp
font.pixelSize: 16
width:parent.width-30
focus:true
font.bold: true
validator: RegExpValidator{regExp: /[0-9A-F]/} // not at all validated
inputMask: ">HHHHHH" // input mask limited for the 6 characters
anchors.fill:parent.Center
anchors {
left: parent.left;
verticalCenter: parent.verticalCenter;
verticalCenterOffset: -1
leftMargin: 5;
}
}
please help if any body has any idea.
Thanks in advance :)
wysota
1st August 2013, 11:27
It seems your regular expression only allows a single digit. Try /[0-9A-F]+/ instead.
Hi wysota,
thanks for your reply, but validation is not at all happening.
not for a single digit too. other validators are working fine. I am displaying the default text inside my TextInput and this is also getting validated before displaying when i use some other validators like intvalidator but in case of regExpValidator, it's not doing any kind of validation.
wysota
1st August 2013, 13:16
Hi wysota,
thanks for your reply, but validation is not at all happening.
not for a single digit too. other validators are working fine.
This works fine for me:
import QtQuick 2.0
Rectangle {
width: 600
height: 300
TextInput {
focus: true
anchors.fill: parent
validator: RegExpValidator { regExp: /[0-9A-F]+/ }
}
}
thanks....its working fine
but the problem is I am setting the text property with some older value which is not a valid input, then this should not display that but it is displaying. do you have any idea why?
wysota
2nd August 2013, 07:49
but the problem is I am setting the text property with some older value which is not a valid input, then this should not display that but it is displaying. do you have any idea why?
Validator works on user input, not on a text set programatically.
i have one more problem with this Validator.
I want to change the validator regular exp by using state change. its able to set the other properties based on the states but not validator.
TextInput
{
id:qVirtualKeyboardTextInput
validator: RegExpValidator { regExp: /[0-9A-Fa-f.-]+/ }
text:EditText
}
states:[
State
{
name:binaryvalidator
when: binaryIOField ==true && decimalIOField=== false
PropertyChanges {
target: TextInput;
validator: IntValidator{bottom:0; top:1} // not working , tried with regExp alsio :(
}
},
State
{
name:decimalvalidator === true
when: decimalIOField
PropertyChanges {
target: TextInput;
//validator: IntValidator{bottom:0; top:9}
inputMask:"9" // able to set the input mask but not validator
}
}
]
can any body tell me why it is not taking. i am getting the error that "component is not ready"
wysota
7th August 2013, 13:33
Define all validators you need and only switch which is currently used.
... {
IntValidator { id: intValidator; ... }
RegExpValidator { id: regexpValidator; ... }
TextInput {
validator: useIntValidator ? intValidator : regexpValidator // you can do the same with PropertyChanges
}
}
hi,
thanks for the reply..I think , I need to use PropertyChanges only because I have more than 3 conditions and I can not use ternary operator for that. Let me try, if it works for me or not.:)
hi wysota,
its working fine with the propertychanges also. only one issue is there. by default my textinput has selected value(displaying it in a highlighted mode). so for the first time input it doesn't go for the validation. If I use the backspace to empty the input field and then if try to give some value to the input field , it goes for the validation and works perfectly. why is it so? any idea?
Thanks in advance :)
wysota
8th August 2013, 07:26
I have already told you -- the validator only work on user input, not on content that is already set in the item.
its working fine
this problem comes only when you have wrong invalidated input value in your input field. I f you have the correctly validated value then it doesn't allow the wrong inputs. Thanks a lot :)
makin it as a Solved thread now.
hi wysota,
its working fine with the propertychanges also. only one issue is there. by default my textinput has selected value(displaying it in a highlighted mode). so for the first time input it doesn't go for the validation. If I use the backspace to empty the input field and then if try to give some value to the input field , it goes for the validation and works perfectly. why is it so? any idea?
Thanks in advance :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.