This seems to be a bug, although maybe it’s just a misunderstanding on my part. I’m initializing a text field with “0” and calling ‘setNumeric(0,16,0)’ to limit the range between 0 and 16, with a default of 0. If I just click on the “OK” button without editing the field, the value returned is 0, but the ‘isValid()’ function returns ‘false’. However, if I edit the field and make a change, even setting it to 0, the ‘isValid()’ function returns ‘true’. Is there something I’m missing?
Thanks. It may seem unimportant, and of course I can write code to do the validation myself, it’s just a simple range-check. But the user isn’t likely to edit the field if the default value is the one he or she wants, they’ll just click on some other field or on the “OK” button. (The default value is within the acceptable range, of course.) Here’s a screen shot of the actual window I was testing when I found the problem. The field in question is “Channel”. If you’re not familiar with MIDI, channel number can be from 1 to 16, to indicate which MIDI channel you want to listen to, or you can select “omni” mode to listen to all channels. I’m using zero to indicate “omni” mode.
I’m not sure I understand why the order of declaration would matter, there’s nothing in the documentation stating that it does, as long as both get called before the window is displayed.
Just to be clear, I think it’s fine to only validate the text during keyboard input, as you say it does. The only problem is with the ‘isValid()’ function, which returns ‘false’ if the field hasn’t been edited, even if the default value is valid.
BTW, there was another question I had in mind.What happens if the default value in ‘setNumeric()’ function is not the same as the value in the ‘setText()’ function? Which value should the ‘getValueI()’ function use, the current text value or the default value in the ‘setNumeric()’ function?
For example, if you changed the line in the code above to this:
textfield1.setNumeric(0,16,1);
I don’t know why anybody would write code like that, unless it’s by mistake, but I was just wondering. The ‘getValueI()’ function seems to be using the default from the ‘setNumeric()’ function, even though the value displayed (the current text value) may be something different. Here’s what happened when I tried it:
In this particular case it doesn’t matter because G4P only tests for validity when the content is changed via the keyboard.
I think the point is that it would be reasonable for the user to assume that G4P perform these actions and the fact that it doesn’t is an omission on my part .
Anyway I have already modified the source code to correct my mistake and they will be in the next release of G4P.