SobiPro - Entry name assembled from multiple fields

Recently I had to build a kind of people directory (ouch, this was  too "politically correct" - in fact a backlist of bad customers for a group of antrepreneurs) and the obvious choice was using of SoBi Pro. But the project has couple of special challenges, and I needed to develop couple of tricks to match my client's needs.

One of this was to have the customer names break down in name, surname, midlle name, fathers name, all entered as separate fields, to be available to filter using each single field. And in the front-end the result needed to be shown as a single field, and this field should be the entry name, both in list and in details field.

 Nice challenge, but is doable!

Here is the recipe for the ones having the same or similar problem.

1. Setting up the entry title.

SoBi can use any SINGLE field as the entry title... so the obvious move was to set up the unified name field, let's say "Full name" (field name was generated by SoBi as field_full_name, to be noted!! will be important later) ,  and set it as the field to be used as the entry title. This is easy. The field is set as a nto required, hidden, freely available, input box type of field, searcheable only via input field.

2. Next step was to set up the name components, these where set up as required, editable, hidden, input box type of fields.

3. With a little CSS trickery the unified name field was hidden in the editor screen:

#field_full_nameContainer {
    visibility: hidden;
}

4.Next step was to hide the partial name fields from details entry.

5.Last, and trickiest step was to collect the data from the four fields, combine them in the aggregated fields and save to the database. Here I used a nice little jQuery script developed by another SoBi user.

Here it is:

/**
* jquery combine input plugin
* Copyright (C) 2012 Mostafa Shalkami, (www.sobimarket.net). All rights reserved.
* License GNU/GPL 2.0 (http://www.gnu.org/licenses/gpl-2.0.html)
**/
jQuery.fn.combineInput = function(fields){
    return this.each(function(){
        var textbox = jQuery(this);
//        textbox.prop('disabled', true);
        jQuery.each(fields, function(index, field) {
            jQuery("#"+field).keyup(function() {
                var fields_values = new Array;
                for (var i = 0; i < fields.length; i++) {
                    fields_values[i] = jQuery("#"+fields[i]).val();
                }
                textbox.val(fields_values.join(' '));
            });
        });
    });
};

Thanks, Moustafa! Save the script above in a separate file, let's say combineinput.js, and upload it to the SoBi template you are using, in the /js subdirectory.

Next you need to hook it up to your template. For this, you need to edit your SoBi template's edit.ini file (if you use the default template, you will find it in this location:

components/com_sobipro/usr/templates/default/entry/edit.ini

and modify the line with the JavaScript inclusions. This is generally looks like:

js_files = "jquery, simplemodal, edit, osx"

Change it to include your new script:

js_files = "jquery, simplemodal, combineinput, edit, osx"

Last step is to trigger it. For this you need to modify the edit.js file - found in the same directory where you uploaded the combineimput.js file, and after this line

window.addEvent( 'load', function() {

add this line:

  jQuery("#field_full_name").combineInput(["field_lastname_f","field_lastname_m","field_name","field_mname"]);

 where, obviously, "field_lastname_f","field_lastname_m","field_name","field_mname" are the field names of fields wich will be combined to have as result the "field_full_name".

And that's it. You have the problem solved, you have the magic done.

 

 

Visit http://sprinklerrepairguy.com to find out more regarding Lawn Irrigation