0

I have 4 decimal fields where user enters can enter price per day, week, month, year. He can choose to enter 1 or more. At least 1 has to be entered of those 4.

Goal is views exposed filter with around 10 filters, all fields in it are mandatory on node creation so there is always result from view, except those 4 mentioned in first place.

Problem is if i add exposed filters for fields day, week, month, year, "betwean" 0 and 100 for each filter, none of the nodes show up on search page (without using the filters yet), as for now, no node has all prices written, and rarely they do. Users usualy put day and week price, or week and month price, or only year price.

On main view page i would atleast like to have all nodes show up with exposed filters in BEF (like they currently do), and then let view when using filters, filter out those who does not have week or month if customers were using filters with those values.

0

You have to implement your own validation logic through a hook_form_alter().

    <?php
    function MY_MODULE_form_alter(&$form, &$form_state, $form_id){
      if ($form_id === 'YOUR_FORM_ID')
        $form$form['#validate'][] = 'YOUR_VALIDATION_FUNCTION';
      }
    }

    function YOUR_VALIDATION_FUCNTION($form, $form_state){
      $assingned_values = 0;
      if(!empty($form_state['values']['FIELD1']['und'][0]['value'])){
        $assigned_values++;
      }
      if(!empty($form_state['values']['FIELD2']['und'][0]['value'])){
        $assigned_values++;
      }
      if(!empty($form_state['values']['FIELD3']['und'][0]['value'])){
        $assigned_values++;
      }
      if(!empty($form_state['values']['FIELD4']['und'][0]['value'])){
        $assigned_values++;
      }
      if ($assigned_values === 0){
        form_set_error('', 'You must set at least one field');
      }
    }
  • Thx Ismail, but i am not good at coding. I was thinking of some sort group field or field collection options. Maybe views can help out, ill clarify the question. – Azz Kawa Jun 8 '16 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.