Hi,
I wrote a wee function (see below) to try to detect if a user has changed anything in a form by searching through the dom tree and testing fields with dialog.getFieldTouched().
However, I've been burned before by doing things with the dom tree and then it changes between versions.
Is there any chance of fourjs supplying a function to detect if the user has changed any values in a form? (hint. feature request). I use this primarily with 'on action cancel' or 'on action accept' to decide whether to warn user about losing changes or to go and save the changes.
Also, if anyone has a better way of testing for any changes easily please post your suggestions, or improvements on function below. Thanks.
function AnyFieldTouched( the_dialog )
define
the_dialog ui.Dialog,
window_ui ui.Window,
window_node om.DomNode,
node_list om.NodeList,
node_item om.DomNode,
i smallint,
field_name string,
field_id string,
change_made boolean
let change_made = FALSE
let window_ui = ui.Window.getCurrent()
let Window_Node = window_ui.getNode()
let node_list = Window_Node.SelectByPath("//FormField")
for i = 1 to node_list.getLength()
let node_item = node_list.item(i)
let field_id = node_item.getAttribute("fieldId") clipped
if length(field_id) then
if node_item.getAttribute("active") = 1 then
let field_name = node_item.getAttribute("name") clipped
if the_dialog.getFieldTouched(field_name clipped) then
let change_made = TRUE
exit for
end if
end if
end if
end for
# above block repeated searching for 'TableColumn' instead of 'FormField' to handle arrays -
# but results not as accurate as doesn't detect deleted row, nor values changed and then changed back as being 'no change'.
return change_made
end function
Regards,
Bryce Stenberg