Home › Forums › General XMetaL Discussion › Adding Additional functionality into Xmetal Validator/F9 › Reply To: Adding Additional functionality into Xmetal Validator/F9
Reply to: Adding Additional functionality into Xmetal Validator/F9February 18, 2013 at 10:17 pm
Note that you might also make such changes automatically if it makes more sense to do so. That assumes you can predict the “mistakes” that users will make and there is only one correction. There is no demo for this, but you can alter a document just before it is saved using On_Before_Document_Save or On_Before_Document_SaveAs. Or you might do it in On_Before_Document_Validate (which fires before both of the previous events and whenever the user presses F9).
One example of what you might do in this case would be to alter the Journalist demo so that it doesn't warn that spaces aren't allowed in that @FileRef but automatically converts them to %20 instead. This could be done inside On_Before_Document_Validate. Then the user doesn't need to worry about entering spaces in @FileRef because they will be changed automatically. Some users might eventually start entering %20 instead (if they notice) but they wouldn't have to.
For users that might be confused by seeing %20 later on (in their XML source or the Attribute Inspector) I would recommend providing an XFT that automatically does the conversion both ways so that when they look at the value in the XFT they see the space (or whatever you are changing) while the XML source remains unaffected, and if they enter a space into the XFT you could also convert it when the XFT is writing out to the XML source (though the On_Before_Document_Validate script would eventually fix those up).
For attributes there is also a special set of events that let you deal with attribute values right after a user has entered them into the Attribute Inspector. They are On_Before_Set_Attribute_From_AI and On_After_Set_Attribute_From_AI. They only fire when the user is interacting with the AI though, so if they change attributes in an XFT you have created you will need to code your logic into the form as well. They might also enter them directly into the XML source in Plain Text view — but in that case do they really need that much hand holding? To be completely “safe”, using the events described at the start of this post would ultimately fix things up so even if you provide this logic in an XFT you may wish to implement one or more of those first events anyway.