Is it possible to validate container fields?

A place for users and developers of the Xataface to discuss and receive support.

Is it possible to validate container fields?

Postby dbaron2 » Sat Oct 03, 2009 5:35 pm

Hello,

Is it possible to validate container fields?

I have a page in my Xataface application with 3 file attachment container fields. I wrote a delegate class validation function to check if the user has entered filenames for uploading. The POST variables are always blank for these container fields:

$_POST['source_attachment_1']
$_POST['source_attachment_2']
$_POST['source_attachment_3']

Is it possible to validate container fields?
dbaron2
 
Posts: 15
Joined: Wed Sep 30, 2009 10:27 pm

Postby Jean » Mon Oct 05, 2009 1:21 am

Bonjour,

Why not use a regex like in this example ?
Code: Select all
[filefield]
validators:regex = "/(.*)[\/\\]([^\/\\]+\.\w+)$/"
validators:regex:message = "any message"


I did not test the regex.

http://xataface.com/documentation/tutorial/getting_started/validation

Jean
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby dbaron2 » Mon Oct 05, 2009 1:36 am

Hello,

Thanks for the suggestion. Unfortunately, I have an unusual requirement where the attachment fields are only required based on another field (status).

If status = 'x' then no attachment is required
If status = 'y' then at least 1 attachment is required
If status = 'z' then at least 2 attachments are required

Because of the unusual requirement I figure I need to code the validation in the table's delegate class.
dbaron2
 
Posts: 15
Joined: Wed Sep 30, 2009 10:27 pm

Postby shannah » Wed Oct 07, 2009 10:52 am

You could do this using javascript rather than validation.

E.g. Create a javascript onchange handler for your status field that hides or shows the container fields according to status. Here is a similar example where I have a select list to choose between paypal and cheque, and two text fields "Cheque payable to", and "Paypal address", where the correct field shows up according to what is selected in the select list. So I create a javascript file:

Code: Select all
jQuery(document).ready(function($){
   
   
   if (typeof(swete) == 'undefined' ) swete = {};
   if ( typeof(swete.tables) == 'undefined')  swete.tables = {};
   swete.tables.affiliate_accounts = {
   
      updatePaymentFields: function(sel){
         if ( jQuery(sel).val() == 'Paypal'){
            jQuery('#paypal_address_form_row').css('display','');
            jQuery('#cheque_payable_to_form_row').css('display','none');
         } else if ( jQuery(sel).val() == 'Cheque' ){
            jQuery('#paypal_address_form_row').css('display','none');
            jQuery('#cheque_payable_to_form_row').css('display','');
         } else {
            jQuery('#paypal_address_form_row').css('display','none');
            jQuery('#cheque_payable_to_form_row').css('display','none');
         }
      }
   };
   
   swete.tables.affiliate_accounts.updatePaymentFields(
      $('#payment_method').get(0)
   );

});


This uses Jquery to make things easier. Jquery is distributed in js/jquery.packed.js.

Then I just include this javascript file before the new and edit record forms by implementing the following in the delegate class:

Code: Select all
function block__before_new_record_form(){
      echo "<script type=\"text/javascript\" src=\"".df_absolute_url(DATAFACE_SITE_URL.'/tables/affiliate_accounts/af
   }
   
   function block__before_edit_record_form(){
      echo "<script type=\"text/javascript\" src=\"".df_absolute_url(DATAFACE_SITE_URL.'/tables/affiliate_accounts/affiliate_accounts.js').'"></script>';

      );
   }

shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 42 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved