Share
Embed
Transcript
17 slides
-
Validations in Oracle Apex Help your users provide meaningful data
a presentation by -
Who am I? • Independent Consultant since 2012 • smart4apex
founding member (2010) • Oracle since 2002 (Oracle 8i) • PL/SQL, Apex, HTML(5), CSS(3), JavaScript, XML, XSLT • Special interest in UI • Trainer at skillbuilders.com • RIMA on Oracle Forums @rhjmartens richardmartens.blogspot.nl Richard Martens -
Why this presentation ? • System security • Prevent SQL
injection • Improve data quality • Help your users • Applications should be usable without reading documentation 4 -
Agenda • Apex Validations • Database constraints – Using the
Error Handling Function • Client side validation – HTML5 validations – Using a JavaScript library -
Apex Validations • 23 !! Different options for validations –
SQL • (no) Rows • Expression – PL/SQL • Expression • Error • Function body (Boolean / error-text) – Item comparison • (not) Null or zero • (not) Contains something • IS (not) a value • Regular Expression – Validations pass when the validation is “true” 6 MOSTLY used -
Apex Validations Regular validations • reference item using :BIND notation
for page item • page vs item validations Tabular Form validations • reference column using :BIND notation for column or pageitem • row vs column validations 7 -
Database constraints • Using real constraints – Table constraints –
Column constraints (not null) – Advantage: easy to maintain at table definition – Disadvantage: cannot use your own code • Using triggers – Advantage: • Can use PLSQL code • Before / After / Statement triggers – Disadvantages • Not as easy to maintain • Error handling function cannot focus on element by default (must write specific plsql code) • Use apex’s “Error handling function” to get meaningful error messages 8 -
The Error Handling Function • Set at application definition •
Map ORA messages to meaningful messages • When check constraint, the element automatically gets selected in the form • Can utilize error messages thrown by triggers (no automatic element-selection) 9 -
Client side validation • HTML(5) / CSS(3) • Dynamic Actions
• JavaScript: – www.w3schools.com/js/js_validation.asp – Validate.js framework • Setup using JavaScript – Parseley framework • Setup using field attributes 10 -
HTML5 / CSS3 validations • Built-in into HTML • Specific
rendering of keyboard on mobile devices – http://html5doctor.com/html5-forms-input-types/ • Apex does not support all types – only text, email, phone-number and url – other types by using a dynamic action to overwrite the “type” attribute • Uses elements attributes – type • color / date / datetime / datetime-local / email / month / number / range / search / tel / time / url / week – autocomplete – formnovalidate – list – min and max – multiple (email / file) – pattern (regexp) – placeholder – required – step – <form> autocomplete – <form> novalidate 11 -
HTML5 / CSS3 validations • Facts & Features – con:
not enforcing • But you can write JavaScript for that – pro: built into the browser, no installation required and backwards compatible – pro: can use CSS to style element 12 -
Javascript frameworks • validatious.org(stand-alone) – http://validatious.org (site seems to be
offline a lot) • validate.js(stand-alone) – http://rickharrison.github.io/validate.js/ • jqueryvalidation.org(jQuery) – http://jqueryvalidation.org/rules • valid8 (jQuery) – http://unwrongest.com/projects/valid8/ • GentleForm – https://github.com/Zhouzi/GentleForm • parsley – http://parsleyjs.org. . . 13 -
Parsley • Uses element attributes • HTML5 compliant • Can
prevent submit when set on form level • http://parsleyjs.org/ • Validators – required – type=“email”/”url” – data-parsley-type=“number” – data-parsley-type=“integer” – data-parsley-type=“digits” – data-parsley-minlegth=“5” – data-parsley-maxlength=“5” – data-parsley-length=“[5, 10]” – data-parsley-equalto="#anotherfield” – … 14 -
Helpfull URLs • https://developer.mozilla.org/en- US/docs/Web/Guide/HTML/Forms/Data_form_validation#Example_that_doesn't_use_the_constraint_validation_API • https://www.smashingmagazine.com/2009/07/web-form-validation-best-practices-and-tutorials/ • http://sixrevisions.com/user-interface/best-practices-for-hints-and-validation-in-web-forms/ •
http://www.alistapart.com/articles/inline-validation-in-web-forms/ 15