HTML in "input/select"

Hi can I add html code in "input/select". For instance text in bold ?

Regards,

 

  • @Hermand Pessek. Yes you can by passing the 'style' keyword in the option of elgg_view( ) or elgg_view_field( ). See example below

    elgg_view_field([

       '#type' => 'select',

       'name' => 'your select name',

       'options_values' => 'array of options',

       'value' => 'can be empty or default value',

       'style' => 'font-weight:bold'

    ]);

  • Thanks. But I want only one "options_values" to be in bold.

    Regards.

  • You should be able to do it with CSS alone
     
    /***Elgg***/
    $name           = 'cars';
    $options        = ['id'=>"carSelect_1234"];
    $options_values = [["volvo"=>"Volvo"],
                                   ["saab"=>"Saab"],
                                   ["mercedes"=>"Mercedes"],
                                   ["audi"=>"Audi']];
     
    elgg_view_field([
       '#type' => 'select',
       'name' => $name,
       'options'=>$options,
       'options_values' => $options_values,
       'value' => 'can be empty or default value',
    ]);
     
    /***CSS***/
    #carSelect_1234>option[value=saab]{font-weight:bold;}
     
    <!--HTML-->
     
    <select name="cars" id="carSelect_1234">
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="mercedes">Mercedes</option>
      <option value="audi">Audi</option>
    </select>
     
  • Correction:

    $options_values = ["volvo"=>"Volvo",
                                   "saab"=>"Saab",
                                   "mercedes"=>"Mercedes",
                                   "audi"=>"Audi'];
Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking