This topic is locked
[SOLVED]

 Help request to complete Select2 plugin

9/16/2020 1:31:37 PM
PHPRunner General questions
fhumanes author

Hi all.
I have some problems in building a plugin that is based on Select2 https://select2.org/
I have selected this plugin because it enables us a lookup (single or multiple value) and adds a free search stage for any string of the displayed values.
This is very important for cases where the possible values ​​of a lookup are many, as it facilitates the search and selection in a simple and "beautiful".
You can see the partial result at https://fhumanes.com/plugines/prueba_plugin6_list.php Link error corrected
You can download the “Select2” plugin in its current state at https://fhumanes.com/blog/guias-desarrollo/plugines-de-phprunner/
I will describe my problems to see if you can help me and also help the rest of the developers, since this plugin will be public so that we can all use it.
NON-SERIOUS PROBLEMS (we could work without them):

  • The version that incorporates PHPRunner of JQuery is very low and therefore we lose the possibility of multi-language, since the javascript of languages ​​gives an error for this library.
  • In PHPRunner when the PHP code receives a Null value as the field value, the value of the field does not change, therefore, in order to delete the values, I have changed to deliver an empty string ('') and when the field is not mandatory (with the possibility to be cleaned), I include a new option with the string ('').


SERIOUS PROBLEM (cannot be used)

  • In the case of multivalued, visually everything works fine, but it only saves the last value of the selected set in the database.


The truth is when I have something that does not work as it should, I look at other developments to see how they have solved it, but in this case, from a field of type "Select", I have nothing and I have not been able to solve it until now.
Any help that you can provide me will be very well received and appreciated.
Greetings,
fernando

fhumanes author 9/16/2020

Hello:
I think I have solved the serious problem and the multiple selection works for me.
The javscript part has remained:



Runner.controls.EditSelect2 = Runner.extend(Runner.controls.Control,{



constructor: function(cfg){

this.addEvent(["change", "keyup"]);

Runner.controls.EditSelect2.superclass.constructor.call(this, cfg);

if (this.getFieldSetting("required")===true) { this.addValidation("IsRequired"); }
$("."+this.valContId).select2.defaults.set("width", this.getFieldSetting("FieldWidth"));



var values = this.getFieldSetting("DefaultValue").split(','); // Create array with valors



var S2 = $("."+this.valContId).select2({

language: this.getFieldSetting("language"),

placeholder: this.getFieldSetting("placeholder") ,

allowClear: this.getFieldSetting("allowClear"),

maximumSelectionLength: this.getFieldSetting("maximumSelectionLength"),

tag: true

});



$("."+this.valContId).val(values); // Select the Value Default

$("."+this.valContId).trigger('change'); // Notify any JS components that the value changed
}

,

isEmpty: function(){

if(this.getValue() === null)

return [];

}

,

getForSubmit: function(){

if (!this.appearOnPage()){ return []; }



console.log("value1: "+this.getValue() );

if (this.getValue() === null ) {

console.log("value NULL");

this.setValue("");

}

if ( typeof this.getValue() == 'object' ) {

var values = this.getValue(); // For transform the array

var values_string = values.join();

var realCb = $("." + this.valContId);

var cbClone = document.createElement('input');

$(cbClone).attr('type', 'hidden');

$(cbClone).attr('id', realCb.attr('id'));

$(cbClone).attr('name', realCb.attr('name'));

$(cbClone).val(values_string);

return [cbClone];

} else {

return [this.valueElem.clone().val(this.getValue())];

}

}



});
Runner.controls.constants["EditSelect2"] = "EditSelect2";


When it is multiple selection the Select2 plugin returns an array and what I do is pass it to a string and with that alone, it did not work.
To make it work I have created a new field with the content of the string and that is what I deliver.
Greetings,

aadham 9/16/2020



Hello:
I think I have solved the serious problem and the multiple selection works for me.
The javscript part has remained:



Runner.controls.EditSelect2 = Runner.extend(Runner.controls.Control,{
constructor: function(cfg){

this.addEvent(["change", "keyup"]);

Runner.controls.EditSelect2.superclass.constructor.call(this, cfg);

if (this.getFieldSetting("required")===true) { this.addValidation("IsRequired"); }
$("."+this.valContId).select2.defaults.set("width", this.getFieldSetting("FieldWidth"));
var values = this.getFieldSetting("DefaultValue").split(','); // Create array with valors
var S2 = $("."+this.valContId).select2({

language: this.getFieldSetting("language"),

placeholder: this.getFieldSetting("placeholder") ,

allowClear: this.getFieldSetting("allowClear"),

maximumSelectionLength: this.getFieldSetting("maximumSelectionLength"),

tag: true

});
$("."+this.valContId).val(values); // Select the Value Default

$("."+this.valContId).trigger('change'); // Notify any JS components that the value changed
}

,

isEmpty: function(){

if(this.getValue() === null)

return [];

}

,

getForSubmit: function(){

if (!this.appearOnPage()){ return []; }
console.log("value1: "+this.getValue() );

if (this.getValue() === null ) {

console.log("value NULL");

this.setValue("");

}

if ( typeof this.getValue() == 'object' ) {

var values = this.getValue(); // For transform the array

var values_string = values.join();

var realCb = $("." + this.valContId);

var cbClone = document.createElement('input');

$(cbClone).attr('type', 'hidden');

$(cbClone).attr('id', realCb.attr('id'));

$(cbClone).attr('name', realCb.attr('name'));

$(cbClone).val(values_string);

return [cbClone];

} else {

return [this.valueElem.clone().val(this.getValue())];

}

}
});
Runner.controls.constants["EditSelect2"] = "EditSelect2";


When it is multiple selection the Select2 plugin returns an array and what I do is pass it to a string and with that alone, it did not work.
To make it work I have created a new field with the content of the string and that is what I deliver.
Greetings,


Thank you very much Fernando.
I find your contributions to be very valuable and I wish I could help but my programming knowledge is rather limited and all I can offer at the moment is a BIG thank you:)
Have a nice day.

fhumanes author 9/17/2020

Thank you very much aadham

fhumanes author 9/17/2020

Hello:
I saw that I had put the plugin test link wrong.
I have already corrected it in the previous message, however I leave you the link so that if you wish you can try it.
DEMO: https://fhumanes.com/plugines/prueba_plugin6_list.php
Except for the multi-language problem, everything else is solved.
Thank you.
fernando

A
alfonsoDevClub member 9/25/2020

How can I install select2 plugin in phprunner 10.4? How can I use later? I've download but I don't see documentation. Thanks

fhumanes author 9/25/2020

Hello:
Plugins are something that PHPrunner has since version 6.2.
This page explains how to install them.
https://xlinesoft.com/plugins
When in the "Designer" option you specify the characteristics of the fields, there you can use any of the plugins you have installed.
The plugin itself explains the parameters it supports.
Regards,
fernando

A
alfonsoDevClub member 9/25/2020

Veo que hablas español. Perdona mi estupidez, pero yo copio la carpeta dentro de C:\Program Files\PHPRunner10.4\source\plugins y no veo que salga la opción. no sé si copia la carpeta correcta: https://monosnap.com/file/4h6W4gVpw9lB13gHCmM1V9l7HeDTpD

Gracias

fhumanes author 9/25/2020

Hola:
En mi caso, con Windows 10, la carpeta de los plugines está en D:\humanes\Documents\PHPRunnerPlugins
Fijate que es un directorio de "Documentos".
Por favor, si necesitas algo más de mi, escríbeme a mi email. fernandohumanes@gmail.com
Saludos,
fernando

A
alfonsoDevClub member 9/25/2020

Gracias. He copiado la carpeta entera dentro de Documents\PHPRunnerPlugins\edit, pero sigo sin ver opciones después. No sé si es que no lo copio en el sitio adecuado o que no copia la carpeta correcta, ya que dentro del script hay varias carpetas Select2