Home » Developer & Programmer » Forms » Trigger to clear then set focus (Forms Developer 10i)
Trigger to clear then set focus [message #628557] Wed, 26 November 2014 05:09 Go to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
I'm trying to make a button that has a trigger that will clear my form, then set focus to an item that is half way through the tab list. This is what I have:

begin
clear_form;
enter_query;
go_item('T_SURNAME');
end;

I cant figure out a way that I can get around it. If I don't put enter_query I cant select other items, but if I do put it, it seems to jump out of the code.
Also, when I press the button again, it sets the focus to the item, but I only want to press the button once.
Any help would be greatly appreciated. Thanks.
Re: Trigger to clear then set focus [message #628560 is a reply to message #628557] Wed, 26 November 2014 05:22 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Once you enter query mode, Forms waits for you to enter search criteria (or not) and execute query. In the meantime, any code you *think* should run does not run (i.e. your GO_ITEM is ignored). There's no way around it.

However, you could reorder block items (in Object Navigator) and put T_SURNAME to be the first enterable item in that block. Doing so, ENTER_QUERY mode would enter query mode and set focus to the first item, which would - in that case - be T_SURNAME.
Re: Trigger to clear then set focus [message #628561 is a reply to message #628560] Wed, 26 November 2014 05:26 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
Thanks for the reply, is there no different way I can do it? its on a mock test I'm doing so there must be some actual way around it as its a high mark question. The exact words of the question are:
"Write a trigger such that when the button is pressed, the form is cleared, and the cursor is placed in the tenants surname field."
I cant really see them writing a question that cant be done in a sensible way, especially when the focus usually goes to the unique ID field.
Thanks
Re: Trigger to clear then set focus [message #628563 is a reply to message #628561] Wed, 26 November 2014 05:32 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
bezzy2829

is there no different way I can do it?

Maybe there is, but I don't know it.
Re: Trigger to clear then set focus [message #628565 is a reply to message #628563] Wed, 26 November 2014 05:34 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Actually, there is (but you fooled me with your code). The question doesn't say that you should enter query mode - it says clear the form. You don't use ENTER_QUERY to do that, you use CLEAR_FORM (as you already did). Then navigate to a desired item with GO_ITEM (specify a block along with the item name, if necessary).

[Updated on: Wed, 26 November 2014 05:35]

Report message to a moderator

Re: Trigger to clear then set focus [message #628567 is a reply to message #628565] Wed, 26 November 2014 05:37 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
When I remove the query line, it gives me the error "FRM-402020: Field must be entered."
It wont let me change the focus unless I put it into query mode.
Re: Trigger to clear then set focus [message #628570 is a reply to message #628567] Wed, 26 November 2014 05:42 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It appears that there are required items placed in front of the T_SURNAME item so you have to enter their values first. So, once again, how about reordering items? Or, just to test it, set "required" properties to "no" and try again.
Re: Trigger to clear then set focus [message #628572 is a reply to message #628570] Wed, 26 November 2014 05:44 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
Is there any way that I can re-order the items in the trigger? So when I press it, it changes so that the surname is first in the order?
Setting required to no works, but the only field before it is for the unique ID, so I need it to be required.
Re: Trigger to clear then set focus [message #628575 is a reply to message #628572] Wed, 26 November 2014 05:47 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Reordering in a trigger: no way.

Required property: can be set with SET_ITEM_PROPERTY built-in. Or, simpler, create WHEN-VALIDATE-RECORD trigger which would check such things, i.e. whether ID is populated or not. How do you populate it, anyway? As it is supposed to be unique, did you let users to enter its value, or is it a sequence (for example) or any other non-human-enterable way?
Re: Trigger to clear then set focus [message #628577 is a reply to message #628575] Wed, 26 November 2014 05:51 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
For this question it is meant to be entered by the user, which is why I'm so puzzled by it, so can I set the property so that it isnt required, then use the WHEN-VALIDATE-RECORD to check that a value is entered. And does the trigger work when a record is to be added?
Re: Trigger to clear then set focus [message #628578 is a reply to message #628577] Wed, 26 November 2014 05:59 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
If user should enter it & you have to go to another item (placed behind the ID item), then you're in a dead loop. You should decide which of these is more important. Usually, you'd enter ID first (at least, that's "usual" for me).

You could do something like this (pseudocode) in the following triggers:
-- WHEN-BUTTON-PRESSED
set_item_property(id, required, false);
go_item(t_surname);

-- WHEN-VALIDATE-ITEM (on t_surname)
set_item_property(id, required, true);

[Updated on: Wed, 26 November 2014 05:59]

Report message to a moderator

Re: Trigger to clear then set focus [message #628580 is a reply to message #628578] Wed, 26 November 2014 06:09 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
Thanks for all the help so far!
For the button pressed code, I get an error that says "Reference ID Not allowed in this context" and another that says "Statement ignored". Any ideas?
Re: Trigger to clear then set focus [message #628582 is a reply to message #628580] Wed, 26 November 2014 06:15 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I hope you didn't literally copy/paste my code?
Re: Trigger to clear then set focus [message #628583 is a reply to message #628582] Wed, 26 November 2014 06:17 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
No, I put the relative field names in, I just didn't put '' around the name. I've fixed that error, but I now get an error from the WHEN-VALIDATE-ITEM of the ID field. It saying the trigger failed on the ID field.
Re: Trigger to clear then set focus [message #628585 is a reply to message #628583] Wed, 26 November 2014 06:20 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Could you post code you wrote?
Re: Trigger to clear then set focus [message #628586 is a reply to message #628585] Wed, 26 November 2014 06:23 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
This is the code in the button:
declare
begin
	clear_form;
	set_item_property('TENANT.TENANT_NO', REQUIRED, PROPERTY_FALSE);
	go_item('T_SURNAME');
end;


This is the code in the WHEN-VALIDATE-ITEM (on t_surname) (Plus the code that was already there)
--
-- Begin default enforce data integrity constraint SYS_C0076702 section
--
set_item_property('TENANT.TENANT_NO', REQUIRED, PROPERTY_TRUE);
if not( :TENANT.T_SURNAME IS NOT NULL ) then
  message( 'WHEN-VALIDATE-ITEM trigger failed on field - ' || :system.trigger_field );
  raise form_trigger_failure;
end if;
--
-- End default enforce data integrity constraint SYS_C0076702 section
--

[Updated on: Wed, 26 November 2014 06:23]

Report message to a moderator

Re: Trigger to clear then set focus [message #628591 is a reply to message #628586] Wed, 26 November 2014 06:31 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
This WHEN-VALIDATE-ITEM trigger re-enforces the "Required" property set to "Yes". So, if T_SURNAME *must* be entered, why didn't you set it to be required? More or less the same as the ID (TENANT_NO) item ...

As I said, if you want to allow users to enter values as they want, WHEN-VALIDATE-RECORD could be the savior, such as
-- WHEN-VALIDATE-RECORD

if :tenant.tenant_no is null then
   message('tenant_no must be entered');
   raise form_trigger_failure;
end if;

if :tenant.t_surname is null then
   message('t_surname must be entered');
   raise form_trigger_failure;
end if;

...
Re: Trigger to clear then set focus [message #628594 is a reply to message #628591] Wed, 26 November 2014 06:39 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
That seems to be working, although, when I press the button it gives the error that tenant number must be entered so it doesnt focus the surname.
Re: Trigger to clear then set focus [message #628595 is a reply to message #628594] Wed, 26 November 2014 06:43 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Did you remove "required" property from TENANT_NO item (in its Property palette)?
Re: Trigger to clear then set focus [message #628599 is a reply to message #628595] Wed, 26 November 2014 06:56 Go to previous messageGo to next message
bezzy2829
Messages: 10
Registered: November 2014
Location: Sunderland
Junior Member
I've got it working now! Thank you so much for all your help!
Re: Trigger to clear then set focus [message #628602 is a reply to message #628599] Wed, 26 November 2014 06:59 Go to previous message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
No problem, I'm glad you fixed it.
Previous Topic: hide value from list of value
Next Topic: forms
Goto Forum:
  


Current Time: Sat Apr 20 03:27:50 CDT 2024