CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • edit in-place validation
Pages: [1]

Author Topic: edit in-place validation  (Read 2169 times)

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
edit in-place validation
September 26, 2013, 03:20:36 am
Hi there

I'm having trouble adding validation to some edit in-place fields.
I'm using views to display some contact's email-addresses, and I've enabled edit in-place for the fields. I've been trying to add validation to the fields, but I cannot wrap my head around how to do it properly.
My fields look like this:
Code: [Select]
<span class="crm-entity" id="email-768"><span class="crmf-email crm-editable crm-editable-enabled" title="Click to edit...">myemail@mydomain.com</span></span>
And as you can see civicrm have added the "crm-editable-enabled"-class.
I can do something like this in a custom js file added to the site:

Code: [Select]
cj('.crmf-email').click(function() {
  cj(".crmf-email form").validate({
    rules: {
      value: {
        required: true,
        email: true
      }
    }
  });
});

Then the form gets loaded to look like this, where you can see the jQuery validation plugin is loaded:
Code: [Select]
<form novalidate="novalidate"><input autocomplete="off" name="value" style="width: 140px; height: 16px;"></form>

The validation plugin should by default validate on keyup, but it doesn't - nomatter if I specify it or not. I've tried to add type="email" as an attribute to the input, and also adding id="value" (same as name, which is given by civcirm), but that doesn't help.
The validation plugin does validate on submit, but the form get's submitted no matter what I write in it (valid or not) - if it's an invalid email-address it briefly displays the "Please enter a valid email address."-message, but the invalid email still gets submitted.

I cannot find anywhere in the docs/wiki/code that describes how to use the validation plugin for a case like this. Is there perhaps some obvious way I have overlooked?
If not an obvious way, can someone guide me to where/what I should change to enable validation on the form before submit? I've tried to take look at the civicrm/js/jquery/jquery.crmeditable.js - but I'm no js-expert, so I cannot figure out where to add the validation, if it should be there.

Thanks in advance for pointers/help/comments :)

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: edit in-place validation
September 26, 2013, 10:30:19 am
When @xavier wrote the in-place edit he probably didn't have jQuery validate in mind, so the edit js won't necessarily wait for jQuery validate to do its thing before it just goes ahead and submits it.
Try asking your question on the new CiviCRM help site.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: edit in-place validation
September 26, 2013, 12:54:10 pm
curious - are you using
https://drupal.org/project/editablefields
https://drupal.org/project/editableviews
or someother magic sauce
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: edit in-place validation
September 26, 2013, 02:28:38 pm
Seems that the magic sauce is jeditable "native civi".

Indeed, didn't have the validation plugin in place. Would be great you investigate what I missed and we should add to properly handle validation.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: edit in-place validation
September 26, 2013, 02:51:00 pm
Some additional info would be much appreciated - is this suggesting there is now a class that can be applied to a field in Views to that renders the field 'editable' with the resulting edit being saved back in to the civi db?

If so how do i do this (my attempts are failing)
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: edit in-place validation
September 26, 2013, 04:22:10 pm
http://wiki.civicrm.org/confluence/display/CRMDOC/Structure+convention+for+automagic+edit+in+place
Try asking your question on the new CiviCRM help site.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: edit in-place validation
September 26, 2013, 05:07:02 pm
Thanks both - will conclude that this is not happening in Drupal VIEWS and that the use of the word 'view' shouldn't have set my nerves trembling in anticipation
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: edit in-place validation
September 26, 2013, 05:10:48 pm
Well that isn't to say you couldn't set up a drupal view with civi edit-in-place functionality, it's probably just a matter of adjusting the wrapper classes for each row to match what the wiki describes. If you get it working maybe we could add a helper for making it easier to set up.
Try asking your question on the new CiviCRM help site.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: edit in-place validation
September 27, 2013, 01:25:54 am
If the needed js are loaded (seems they are), it's indeed simply a matter of adding 3 classes and one id.

If possible and contrary to the initial example, it'd be better to put the entity and id on the row and the field on the td (or span inside, but not sure what would be the benefit). If you mix several entities (eg contact at the row and email as a separate column, this is the right way indeed)

so if you can adjust views to output

Code: [Select]
<tr class="crm-entity" id="email-768">
<td>primary<td>
<td class="crmf-email crm-editable">myemail@mydomain.com</td>
</tr>


Not sure how much your nerves are going to tremble after that, but you should be all edited in place. 
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: edit in-place validation
September 27, 2013, 10:03:30 am
It is as Xavier shows quite easy to add in place editing in a views table. I have several fields in my views tabel - fx. first_name, last_name and email so I have id='contact-[id]' in the row tag, but that want work for the email field, thus the extra span tag in my example for the email field.

Still can anyone point me to where I should add the js for validation if I want to validate while editing the form before submit? I cannot figure out why my attempt doesn't work - to be precise, why it doesn't validate on keyup, as is default for the validation plugin, especially since it does validate on submit (though the validation error is ignored and the form submitted anyways).

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: edit in-place validation
October 04, 2013, 05:25:24 pm
Could you check it it's already possible to easily integrate the two plugins we use? jeditable and validate. It's probably simple to adjust the submit so it doesn't if the validation has failed

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • edit in-place validation

This forum was archived on 2017-11-26.