I’m trying to highlight fields that need a users attention (maybe they put some bad data or are missing data).
I set out to use WebTextField.Indicator but the fields don’t seem to react to changes to that property. So then I tried simply changing the style of the background to something like this…
…that works great. However, I wanted to use the .GotFocus event of the field to restore the .BackgroundColor… but, that event doesn’t seem to fire.
I can manage to get the .TextChanged event to react, so I thought I’ll just use that to reset the background, which appears to work, but then after testing I see that as a user types into that field that an occasional backspacing happens and arbitrarily backspaces over one of the entered characters!
Is this known behavioral issues with WebTextField’s?
There is a bug that the GotFocus doesn’t fire if you click a WebTextField (TABbing in/out works). The bug is marked fixed so next Xojo release should have that fixed.
Haven’t seen that reported, can you create a sample application and/or video about this?
Here is the login window I’m working on now and it exhibits the issues. If you 'submit bad credentials the fields turn yellow - if you try backspacing over your bad password and start retyping it you’ll see how the input gets hijacked and backspaces over your ongoing entry.
When rendering, some Xojo Web controls will set their properties whether they need it or not. I haven’t investigated this particular scenario, but this is the kind of thing I expect when the following is happening:
User is typing
Changed event fires
BackgroundColor is set
User is still typing…
Control is re-rendered client-side, overwriting the current field value
User is still typing…
If that’s the case, there will be lost information. As I said, haven’t checked this specifically but from what I’ve seen of the framework this seems likely. I wouldn’t change the BackgroundColor or, really, any other property from TextChanged.
Well, you could do something like this in TextChanged:
if me.Text.Length > 0 then
ExecuteJavaScript( "$('#" + me.ControlID + "_field').addClass('is-valid').removeClass('is-invalid');" )
else
ExecuteJavaScript( "$('#" + me.ControlID + "_field').addClass('is-invalid').removeClass('is-valid');" )
end if
This wouldn’t trigger the re-render and would give validation information directly in the component using the built-in Bootstrap classes. I’d probably create a subclass of WebTextField and store state so that you only update it when needed.
An alternative would be to grab GraffitiSuite. I have a ton of extra functions, properties, and abilities built in to my components for things like this.
…it sure would make it more simple if the actual (documented) behavior of the controls worked I appreciate the scripting suggestions - look forward to getting onto the next task - I always get stuck going down the rabbit hole on these things.
I’m going to check out GraffitiSuite - if it solves problems and doesn’t have a large learning curve then Yes Please!
You could also do something like this, if you’re into JavaScript, using the TextField’s Shown event. This will work as-is if your control’s Shown event only fires once, but if it’s hidden and shown multiple times then it could bog things down a bit as you’ll be firing the event multiple times on each input.
Sub Shown() Handles Shown
var exec() as String
exec.Add( "var $this = $('#" + me.ControlID + "_field');" )
exec.Add( "$this.on('input', function (e) {" )
exec.Add( " if (this.value.length == 0) {" )
exec.Add( " $(this).addClass('is-invalid').removeClass('is-valid');" )
exec.Add( " } else {" )
exec.Add( " $(this).addClass('is-valid').removeClass('is-invalid');" )
exec.Add( " }" )
exec.Add( "});" )
ExecuteJavaScript( String.FromArray( exec, "" ) )
End Sub
This has the added benefit of not relying on two-way communication to validate the field contents.
I can vouch to the quick support from Anthony.
Between Graffitisuite and @Tim_Parnell 's TP_Webkit (which fixes some of the missing functionality of the webtextfield like gotfocus and lostfocus among others) web 2.0 has been a lot more manageable.