Jump to content

Trying to hide field title and suffix when empty


jodancer

Recommended Posts

I have a text field which I am trying to hide the name, suffix and prefex when the field value is empty.

 

Been trying for I just cannot make it work. (pretty useless I know!)

 

Could anyone take a look and point me in the right direction?

 

many thanks

Link to comment
Share on other sites

Hi,

 

Thanks for the reply.

 

I have a number of fields and these have a title a possible suffix or prefix

 

Example

 

Number of Bedrooms: 4 Double

 

In this case the

 

Number of Bedrooms is the Title of the field

 

4 is the input value

 

Double is the prefix

 

If the field is not filled in (in this case 4) then I would like Number of bedrooms and Double hidden

Link to comment
Share on other sites

Sorry, I did attach a file but it sems to have disappeared!

 

<?php defined( 'cliff' ) or die( 'Restricted access' );?>
<?php
class GExtrafieldTextText extends GElement{
public function renderInput($name, $value, &$node, $control_name)
{
 $parameters = & JRegistry::getInstance ($node);
 $parameters->loadJSON($node);

 $required    = $parameters->get( 'required', 0 ) ;
 //$size    = ($parameters->get('field_size') ? 'size="'.$parameters->get('field_size').'"' : '');
 $default_value  = $parameters->get( 'default_value', '' ) ;
 $prefix    = $parameters->get( 'prefix_text', '' ) ;
 $suffix    = $parameters->get( 'suffix_text', '' ) ;
 $required    = $required ? ' validate[required]' : '';
 $class	 = 'class="lbinputbox'.$required.$parameters->get('field_class').'"';
 // Required to avoid a cycle of encoding &
 $value = htmlspecialchars(htmlspecialchars_decode($value, ENT_QUOTES), ENT_QUOTES, 'UTF-8');
 if($value=="")
 {
  $value = $default_value;
 }
 $input = "";
 $input .= "<span class=\"input\">";
 $input .= $prefix;
 $input .= "</span>";
 $input .= '<input type="text" name="'.$control_name.'['.$name.']" id="'.$control_name.$name.'" value="'.$value.'" '.$class.' />';
 $input .= "<span class=\"input\">";
 $input .= $suffix;
 $input .= "</span>";
 return $input;
}
function renderValue($data)
{
 $registry = & JRegistry::getInstance ($data->params);
 $registry->loadJSON($data->params );
 $prefix    = $registry->get( 'prefix_text_view', '' ) ;
 $suffix    = $registry->get( 'suffix_text_view', '' ) ;
 // Required to avoid a cycle of encoding &
 $value = htmlspecialchars(htmlspecialchars_decode($data->actual_value, ENT_QUOTES), ENT_QUOTES, 'UTF-8');
 $output = "";
 if($prefix!="")
 {
  $output .= "<span class=\"input\">";
  $output .= $prefix;
  $output .= "</span>";
 }
 $output .= $value;
 if($suffix!="")
 {
  $output .= "<span class=\"input\">";
  $output .= $suffix;
  $output .= "</span>";
 }
 return $output;
}
function renderSearchInput($name, $value, &$node, $control_name)
{
 $parameters = & JRegistry::getInstance ($node);
 $parameters->loadJSON($node);
 //$size    = ($parameters->get('field_size') ? 'size="'.$parameters->get('field_size').'"' : '');
 $default_value  = $parameters->get( 'default_value', '' ) ;
 $prefix    = $parameters->get( 'prefix_text', '' ) ;
 $suffix    = $parameters->get( 'suffix_text', '' ) ; 
 $class	 = 'class="lbinputbox'.$parameters->get('field_class').'"';
 // Required to avoid a cycle of encoding &
 $value = htmlspecialchars(htmlspecialchars_decode($value, ENT_QUOTES), ENT_QUOTES, 'UTF-8');
 if($value=="")
 {
  $value = $default_value;
 }
 $input = "";
 $input .= "<span class=\"input\">";
 $input .= $prefix;
 $input .= "</span>";
 $input .= '<input type="text" name="'.$control_name.'['.$name.']" id="'.$control_name.$name.'" value="'.$value.'" '.$class.' />';
 $input .= "<span class=\"input\">";
 $input .= $suffix;
 $input .= "</span>";
 return $input;
}
function beforeStoreInput($extrafield,&$data, $files)
{

 $err_msg = "";
 if(!is_null($data))
 {
  if(key_exists($extrafield->fieldcode, $data))
  {

   $registry = & JRegistry::getInstance ($extrafield->id);
   $registry->loadJSON($extrafield->params );

   $required  = $registry->get( 'required', 0 ) ;
   if($required && empty($data[$extrafield->fieldcode]))
   {
 $err_msg = JText::_('TEXT_EXTRAFIELD_REQUIRED');
   }
   else {

 if($data[$extrafield->fieldcode]!="")
 {
  $filter = GFilter::factory('string');
  $data[$extrafield->fieldcode] = $filter->sanitize($data[$extrafield->fieldcode]);
 }
   }
  }
 }
 return $err_msg;
}

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.