Quantcast

->rendorform and displaying errors inline

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

->rendorform and displaying errors inline

Trevor Borgmeier
I'm relatively new to knop since I've mostly been living in a PHP world
the last couple of years (mostly due to pressure from an otherwise good
client), but am wanting to edge my way back toward lasso and lasso 9.

Anyway, playing with knop I noticed it couldn't easily (AFAIK) display a
field error along with a field.  The ToDo list seems to suggest this as
well stating that:

->renderform needs a better way to display errors inline together with
the fields

Since I wanted this functionality, my first thought was to integrate a
new replace method for the template function...  So I added this code at
line 1361 of the form.inc file (LP8.x version of knop):

> // set field error message if exists...
> if: (self -> 'errors') -> type == 'array' && (self -> 'errors') >>
> (#onefield -> (find: 'name'));
>         #renderrow -> (replace: '#error#', ('<span ' + #errorclass +
> '>' + (self -> errors -> find(#onefield -> (find:'name')) -> first ->
> value) + '</span>'));
> else;
>         #renderrow -> (replace: '#error#', '');
> /if;
Now I can do this...

var(
     'form'=knop_form(-template='<div>#label##required##error#<br
/>#field#</div>')
);

It may not be ideal reusing the #errorclass parameter for both the label
and the span, but it's still easy to style them different by targeting
them appropriately via css.

label.fielderror
span.fielderror

Given I'm new to knop, if I've added anything stupid or overlooked
anything please let me know.

Also, what's the process for updating the repository / getting code
accepted into the source?

-Trevor

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lasso.2283332.n4.nabble.com/Knop-Framework-Discussion-f3157831.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ->rendorform and displaying errors inline

stevepiercy
On 2/29/12 at 2:40 AM, [hidden email] (Trevor Borgmeier) pronounced:

>Anyway, playing with knop I noticed it couldn't easily (AFAIK)
>display a field error along with a field.  The ToDo list seems
>to suggest this as well stating that:
>
>->renderform needs a better way to display errors inline together with the fields

I developed a technique for this.  You can try out an example on
one of my sites by leaving fields blank:
http://www.norcalreferees.com/sendoff/

Details of my technique are in the list archive, with an example
screenshot attached to the message.
http://lasso.2283332.n4.nabble.com/Display-validation-error-messages-next-to-each-field-tp3158885p3158887.html

Do you have a working example already, or at least a screenshot?

>Since I wanted this functionality, my first thought was to
>integrate a new replace method for the template function...  So
>I added this code at line 1361 of the form.inc file (LP8.x
>version of knop):
>
>>// set field error message if exists...
>>if: (self -> 'errors') -> type == 'array' && (self -> 'errors')
>>>> (#onefield -> (find: 'name'));
>>#renderrow -> (replace: '#error#', ('<span ' + #errorclass +
>>'>' + (self -> errors -> find(#onefield -> (find:'name')) ->
>>first -> value) + '</span>'));
>>else;
>>#renderrow -> (replace: '#error#', '');
>>/if;

This looks good.

Suggest adding the ability to iterate through the array of error
messages, instead of just grabbing only the first error for a
field.  For example, a required US ZIP Code could have 2 error messages:

ZIP Code is required
ZIP Code must consist of 5 numbers

Or maybe not iterate but ->join with a delimiter (like <br />).

Otherwise the user must repeatedly submit the form, getting the
next validation error message until they finally get through
each possible error for that one field.

>Now I can do this...
>
>var(
>'form'=knop_form(-template='<div>#label##required##error#<br />#field#</div>')
>);
>It may not be ideal reusing the #errorclass parameter for both
>the label and the span, but it's still easy to style them
>different by targeting them appropriately via css.

Suggest using a separate class by adding a new parameter to the
tag.  Just duplicate code that refers to "-errorclass", and
rename it to, say "-validationclass".  Thus this class is
implied to be used only upon validation of a field, and not some
other error (database, etc.).

>label.fielderror
>span.fielderror
>
>Given I'm new to knop, if I've added anything stupid or
>overlooked anything please let me know.
>
>Also, what's the process for updating the repository / getting
>code accepted into the source?

There is no formal process.  I think Johan is the admin, or
perhaps Jolle, too, now.  I have write access so I can commit
files to the repo.  There may be a few other folks.

Changes are always welcome.  Here are some common sense guidelines:

You should make your change stupid easy to accept by others.

Proposed changes should be reviewed by peers.

Changes should not break any existing functionality, although
there are valid exceptions.  I made one change that broke the
ability to use dots in field names in Filemaker and the trade
off was to gain the ability to do JOINs in MySQL.  In this case,
folks here agreed that it would be more useful to accept the change.

Changes should be documented.  See examples in the core .inc
files of how to do this.

You should make changes in core .inc files, then run the Knop
build process to generate the knop.lasso library file.

Once done, you can either attach the files to an email to the
list so others can download and incorporate them, and committers
can commit files to the repo.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lasso.2283332.n4.nabble.com/Knop-Framework-Discussion-f3157831.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ->rendorform and displaying errors inline

Johan Solve-2
Good guidelines!

At 02.38 -0800 2012-02-29, Steve Piercy - Web Site Builder wrote:

>There is no formal process.  I think Johan is the admin, or perhaps Jolle, too, now.  I have write access so I can commit files to the repo.  There may be a few other folks.
>
>Changes are always welcome.  Here are some common sense guidelines:
>
>You should make your change stupid easy to accept by others.
>
>Proposed changes should be reviewed by peers.
>
>Changes should not break any existing functionality, although there are valid exceptions.  I made one change that broke the ability to use dots in field names in Filemaker and the trade off was to gain the ability to do JOINs in MySQL.  In this case, folks here agreed that it would be more useful to accept the change.
>
>Changes should be documented.  See examples in the core .inc files of how to do this.
>
>You should make changes in core .inc files, then run the Knop build process to generate the knop.lasso library file.
>
>Once done, you can either attach the files to an email to the list so others can download and incorporate them, and committers can commit files to the repo.
>
>--steve
>
>-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>Steve Piercy               Web Site Builder
>Soquel, CA
><[hidden email]>                  <http://www.StevePiercy.com/>
>
>
>--
>#############################################################
>This message is sent to you because you are subscribed to
>the mailing list <[hidden email]>.
>To unsubscribe, E-mail to: <[hidden email]>
>Send administrative queries to  <[hidden email]>
>List archive http://lasso.2283332.n4.nabble.com/Knop-Framework-Discussion-f3157831.html
>Project homepage http://montania.se/projects/knop/
>Google Code has the latest downloads at http://code.google.com/p/knop/


--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lasso.2283332.n4.nabble.com/Knop-Framework-Discussion-f3157831.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Loading...