I am trying to create a reset button to clear the form, however i get stopped when my text field is empty.
IF (:TREATMENT_BLOCK.TR_NAME IS NULL) THEN
MESSAGE('Treatment Name field is required.');
RAISE FORM_TRIGGER_FAILURE;
END IF;
I implemented this piece of code in the WHEN_VALIDATE_ITEM but its not working, i cannot bypass the trigger failure to reset the form even if my text fields are null.
Set form validation to false; clear form, and return it back to true.
declare
fm_id formmodule;
begin
fm_id := find_form(:system.current_form);
set_form_property(fm_id, validation, property_false);
--
clear_form;
--
set_form_property(fm_id, validation, property_true);
end;
Because, when you set the property to false,
... all internal form validation will be bypassed and no WHEN-VALIDATE triggers will fire.
Related
I have a couple of text fields that are filled from the database when the value of a select list changed.
I added another action to the list change dynamic action to execute PL/SQL code:
IF :P2_SELECT_LIST1 LIKE '%ABC%' AND :P2_NAME = 'WWW' THEN
:P2_NAME = NULL;
END IF;
Nothing happend on the page when I change the value of the select list, but the session value of P2_NAME gets cleared.
I also tried:
IF :P2_SELECT_LIST1 LIKE '%ABC%' AND :P2_NAME = 'WWW' THEN
:P2_NAME = '';
END IF;
But gotten the same result
In this dynamic action there are two fields next to your pl/sql code:
Items to submit: list the items here that you use in your pl/sql to get the values from session (if necessary, the values are usually already in session).
Items to return: list the items here that you need to refresh the value on the HTML page after some change in your pl/sql
I think this solves the problem.
I created form for customers, I need to do validate customer name like
1 - type the new name into item P1_CUST_NAME.
2 - after leaving this item go to database and check if this name already exist or not.
3 - display alert or message for the client.
4 - prevent the client from navigating a way from this item until he enter valid data.
Yes, you can create server side validation by using Dynamic Action and JavaScript function apex.server.process.
A basic example to demonstrate-
Create a page item e.g. P4_NAME in your page
Create a page process and select the execution point as "AJAX
CALLBACK".
In below code I am checking the P4_ITEM value, you can write your own logic to validate.
BEGIN
IF :P4_NAME = 'HIMANSHU'
THEN
HTP.prn ('SUCCESS');
ELSE
HTP.prn ('ERROR');
END IF;
END;
Now create a new dynamic action and select the Event as "LOSE FOCUS", Selection Type as "Item(s)" and in Item(s) select the item name.
Create a true action and select "execute JavaScript Code".
In code section, implement apex.server.process like below-
apex.server.process('validate_name',
{
pageItems : '#P4_NAME'
}
,
{
dataType : 'text', success : function(data)
{
if(data != 'SUCCESS')alert(data);
}
}
)
The first argument is the page process name(validate_name) which we have create earlier, second the data you want to submit to the process and third is options.
For more details on apex.server.process
It is done. Refresh your page and check. On validation failure you will get an alert.
You can customize your JS code further to display error messages in more fancy way instead of showing alert.
I have a validation on a text field. After a submit page button is pressed, I want the validations to check the code below and return a plsql text if it fails. Once the validation returns null(as in no issue) an after submit proccess should occur. The issue is, the after submit proccess still occurs and the validations are only producing >> ELSE RETURN 'Invalid email address'; rather than any of the other e.g. invalid email address if there's no text in the field. Oh an also I have a server side condition on the field to work when the button is clicked.
Help would be really appreciated. Thank you.
Edit: thanks for editing. I did have the BEGIN in it before I just forgot to add it to this post. The issue is still ongoing.
BEGIN
IF (INSTR(:P101_NEW_2, '#gmail.com') > 0) THEN RETURN NULL;
ELSIF (INSTR(:P101_NEW_2,'#hotmail.com) > 0) THEN RETURN NULL;
ELSIF (INSTR(:P101_NEW_2,'#yahoo.com') > 0)THEN RETURN NULL;
ELSIF (:P101_NEW_2 = NULL) THEN RETURN 'Input Email Address';
ELSIF (INSTR(:P101_NEW_2, '#gmail.com') < 1) OR (INSTR(:P101_NEW_2,'#hotmail.com') < 1) OR (INSTR(:P101_NEW_2,'#gmail.com') < 1) THEN RETURN 'Input Email Address';
ELSE RETURN 'Invalid email address';
END IF;
COMMIT;
END;
I believe I've solved it. It's validation with PL/SQL Function (returning text). I did not create a function as you can see from the above code. I'll create a function and include that code and let you know how I get on.
Email address validations typically validate the format, but that's up to you.
not REGEXP_LIKE(:P1_EMAIL, '^[^.]([a-zA-Z0-9_''\+\.\-]+)[^.]#[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9\-]+)*(\.[a-zA-Z]{2,})$')
Validations aim for true/null, so if there is a problem then depending on the type it will return false or a message to display.
If you compare :P1_EMAIL = null, it will always return false. Nothing is ever = null. It should be :P1_EMAIL is null
Your penultimate condition might as well be :P1_EMAIL is not null, since you've checked content and null-ness.
You only need begin/end if you have declare or exception sections.
And you will rarely need a commit in APEX.
Is it possible to execute validations on page load regardless if it is submitted or just loaded?
I need to implement it for ordinary validations created in processing page section and for min max validations assigned to number field.
Is it possible to implement?
Indeed: having a server side validation will throw an error, but the page has submitted and thus the changed values are in session state. You could try to prevent this by having a plsql validation which would blank out the session state value when an error occurs, but might not be optimal. I think that some javascript could alliviate some of the trouble.
Here is some javascript that restricts the selectable ranges in the to and from datepickers. It won't allow a user to pick a larger from than to date, and vice versa. It also sets the item to readonly, so that the user has to select through the datepicker and can not alter it by hand.
Page > Javascript > Function and Global Variable Declaration
function f_check_date(){
var lFrom = $("#P6_DATE_FROM").datepicker("getDate"),
lTo = $("#P6_DATE_TO").datepicker("getDate");
if(lFrom > lTo || lTo < lFrom){
//in case it does happen
$("#P6_DATE_FROM").val('');
$("#P6_DATE_FROM").val('');
alert('Please select a valid date range.');
} else {
//when a date changes, the other datepicker has to be altered so the
//range is adjusted
$("#P6_DATE_FROM").datepicker("option","maxDate",lTo);
$("#P6_DATE_TO").datepicker("option","minDate",lFrom);
};
};
Dynamic Action, Page Load, Execute javascript
//on load, set the datepicker range in case a date is already present
//when the date changes, call the datecheck function
//and set item to readonly
$("#P6_DATE_FROM")
.datepicker("option","maxDate",$("#P6_DATE_TO").datepicker("getDate"))
.change(f_check_date)
.prop("readonly",true);
$("#P6_DATE_TO")
.datepicker("option","minDate",$("#P6_DATE_FROM").datepicker("getDate"))
.change(f_check_date)
.prop("readonly",true);
I'm using MVC3 .NET4.0 (VB), and I'm seeing some strange behavior on a simple View. It's a Create view that is set up as:
Inherits="System.Web.Mvc.ViewPage(Of MyProject.MyTable)
The controller is pretty straightforward. It accepts the ID of the parent record to which this record is being added:
Function Create(parent As Integer) As ActionResult
Return View(New MyTable With {.parent_id = parent})
End Function
The View also accepts a date among other things, but it boils down to this:
<% Using Html.BeginForm()%>
<%=Html.ValidationSummary(True)%>
<%=Html.DisplayFor(Function(model) model.parent_id)%>
<%=Html.TextBoxFor(Function(model) model.start_date)%>
<%=Html.ValidationMessageFor(Function(model) model.start_date, "*")%>
<button type="submit" id="submitButton">Save</button>
<% End Using%>
I'm testing the handling of date errors, so right now my post controller is just checking for errors and not doing much else:
<HttpPost()>
Function Create(model As MyTable) As ActionResult
If ModelState.IsValid Then
Return RedirectToAction("Index")
Else
Return View(model)
End If
End Function
When I first load the view, I see the parent ID displayed on the form. If I put a bad date into the start date field and hit Submit, the form comes back with the invalid value highlighted, but the parent ID = 0. If I break the code in the post, I can see that "model" doesn't have the parent ID set. This obviously causes all kinds of problems, because I've essentially lost who the parent is. What am I doing wrong?
UPDATE
Per Darin's suggestion I changed DisplayFor to HiddenFor and didn't see any difference. So then I tried TextBoxFor and got stranger results. I still don't see the parent ID in the post function, but the value persists in the text box.
What am I doing wrong?
You are not including the parent_id as hidden field in your form. Inside your form you have a single input element which corresponds to the start_date field, so that's all that you can hope to get in your POST action.
So:
<%= Html.HiddenFor(Function(model) model.parent_id) %>
The DisplayFor that you used only displays the value, it doesn't emit any input field to transport this value to the server when the form is submitted.