Sten Ka Razin
Sten Ka Razin

Reputation: 993

provide a combination of Salutation and Firstname with vtiger 6.4 uitype=55

In a custom module I'd like to create a combination of salutation and firstname fields, exactly as the one present on Leads module. I'm using vtlib to create my module. I have created the following field:

 $field2  = new Vtiger_Field();
 $field2->name = 'firstname';
 $field2->label= 'Firstname';
 **$field2->uitype= 55;**
 $field2->column = $field2->name;
 $field2->columntype = 'VARCHAR(255)';
 $field2->typeofdata = 'V~O'; // Varchar Optional field
 $block->addField($field2);

This doesn't work as expected, and create only a text field without salutation field.

At https://wiki.vtiger.com/index.php/UI_Types we can read about uitype=55:

"This uitype provides a combination of Salutation and Firstname. The Salutation field is a dropdown while the Firstname field is a single line textfield which changes its colour on selection."

So I was wondering if I have to create a new pick list for salutation (Can we reuse the existent one ?) , and how to bring togheter them into one line with a unique Firstname label.

Any ideas?

Regards

Upvotes: 0

Views: 382

Answers (1)

Sten Ka Razin
Sten Ka Razin

Reputation: 993

Ok got it. In the vtlib script I have added something like this:

  $field0  = new Vtiger_Field();
  $field0->name = 'salutationtype';
  $field0->label= 'Salutation';
  // This uitype provides a combination of Salutation and Firstname. The Salutation field is a dropdown w$
  $field0->uitype= 55; // A single line textfield. Changes colour when selected.
  $field0->column = 'salutation';
  $field0->columntype = 'VARCHAR(20)';
  $field0->typeofdata = 'V~O'; // Varchar Optional field
  $field0->displaytype = 3; // Hide from view
  $block->addField($field0);

  $field1  = new Vtiger_Field();
  $field1->name = 'firstname';
  $field1->label= 'First Name';
  // This uitype provides a combination of Salutation and Firstname. The Salutation field is a dropdown w$
  $field1->uitype= 55; // A single line textfield. Changes colour when selected.
  $field1->column = $field1->name;
  $field1->columntype = 'VARCHAR(255)';
  $field1->typeofdata = 'V~O'; // Varchar Optional field
  $block->addField($field1);

Then I have created the following file: modules/MyModule/views/Edit.php

class MyModule_Edit_View extends Vtiger_Edit_View {

  public function process(Vtiger_Request $request) {
    $moduleName = $request->getModule();
    $recordId = $request->get('record');
    $recordModel = $this->record; 

    if(!$recordModel){
      if (!empty($recordId)) {
        $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
      } else {
          $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
        }
    }

    $viewer = $this->getViewer($request);

    $salutationFieldModel = Vtiger_Field_Model::getInstance('salutationtype', $recordModel->getModule());
    $salutationType = $request->get('salutationtype');
    if(!empty($salutationType)){ 
      $salutationFieldModel->set('fieldvalue', $request->get('salutationtype')); 
    } 
    else{ 
      $salutationFieldModel->set('fieldvalue', $recordModel->get('salutationtype')); 
    } 
    $viewer->assign('SALUTATION_FIELD_MODEL', $salutationFieldModel);
    parent::process($request);
  }
}

And now it works as expected.

Upvotes: 0

Related Questions