Changeset 5390

Show
Ignore:
Timestamp:
02/19/07 14:40:45 (2 years ago)
Author:
rambo
Message:

attempt to load type specific QF rules (this part works) and use them for example to make required multiselects to work (validator is registered correctly but for some reason never called)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/midcom.helper.datamanager2/formmanager.php

    r5372 r5390  
    164164    } 
    165165 
     166    function _load_type_qfrules($fieldname) 
     167    { 
     168        $config = $this->_schema->fields[$fieldname]; 
     169        $filename = MIDCOM_ROOT . "/midcom/helper/datamanager2/QuickForm_rules/{$config['type']}.php"; 
     170        $classname = "midcom_helper_datamanager2_qfrule_{$config['type']}_manager"; 
     171        if (class_exists($classname)) 
     172        { 
     173            // We have already initialized rules for this type 
     174            return; 
     175        } 
     176        if (!file_exists($filename)) 
     177        { 
     178            // no file for this type found, skip silently 
     179            return; 
     180        } 
     181        include_once($filename); 
     182        $manager = new $classname(); 
     183        $manager->register_rules($this->form); 
     184    } 
     185 
    166186    /** 
    167187     * This function fully initializes the class for operation. This is not done during the 
     
    487507    function _add_rules_and_filters($name, $config) 
    488508    { 
     509        $this->_load_type_qfrules($name); 
    489510        $widget =& $this->widgets[$name]; 
    490511        if ($config['readonly']) 
     
    529550                      && !is_a($type, 'midcom_helper_datamanager2_type_images')): 
    530551                    // 'required' does not work for uploads -> use 'uploadedfile' 
     552                    // OTOH: Does this mean it requires new upload each time ?? TODO: Test 
    531553                    $this->form->addRule($name, $message, 'uploadedfile', ''); 
    532554                    break; 
    533555                // Match all other blobs types (those allow multiple uploads which are kind of hard to validate) 
    534556                case (is_a($type, 'midcom_helper_datamanager2_type_blobs')): 
    535                     // How will you require-validate N uploads ?? 
     557                    // PONDER: How will you require-validate N uploads ?? (also see the point about existing files above) 
    536558                    debug_push_class(__CLASS__, __FUNCTION__); 
    537559                    debug_add("types with multiple files cannot have required validation (field name: {$name})", MIDCOM_LOG_ERROR); 
     
    539561                    break; 
    540562                // Match select types (have array data, 'required' will choke on them) 
    541                 case (is_a($type, 'midcom_helper_datamanager2_type_select')): 
    542                     // TODO: register callback 
    543                     debug_push_class(__CLASS__, __FUNCTION__); 
    544                     debug_add("select types cannot have required validation ATM (field name: {$name})", MIDCOM_LOG_INFO); 
    545                     debug_pop(); 
     563                case (   is_a($type, 'midcom_helper_datamanager2_type_select') 
     564                      && $type->allow_multiple): 
     565                    debug_add("Callign this->form->addRule('{$name}', '{$message}', 'requiremultiselect', '');"); 
     566                    $stat = $this->form->addRule($name, $message, 'requiremultiselect', ''); 
     567                    if (is_a($stat, 'pear_error')) 
     568                    { 
     569                        $msg = $stat->getMessage(); 
     570                        debug_push_class(__CLASS__, __FUNCTION__); 
     571                        debug_add("Got PEAR error '{$msg}' from this->form->addRule('{$name}', '{$message}', 'required_multiselect', ''), when adding multiselect required rule", MIDCOM_LOG_WARN); 
     572                        debug_pop(); 
     573                    } 
    546574                    break; 
    547575                // Other types should be fine with the default string validation offered by 'required' 
     
    672700        { 
    673701            // Validate the from. 
     702            debug_push_class(__CLASS__, __FUNCTION__); 
     703            debug_print_r('this->form', $this->form); 
     704            debug_print_r("\$GLOBALS['_HTML_QuickForm_registered_rules']", $GLOBALS['_HTML_QuickForm_registered_rules']); 
     705            debug_pop(); 
    674706            if (! $this->form->validate()) 
    675707            {