Hi,
For what its worth I find myself doing the same thing on a component I am developing.
It would be nice if there was an api for this but it doesn't seem there is one.
I wonder how easy it would be to add...or if its planned?
Ads
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
AJH <aaron.hu
...@gmail.com> wrote:
I apologize for the somewhat incoherent question I originally posted. It was late :-)
My component allows for new fields to be defined by the end-user for any object that supports it within the component.
I accomplished this by subclassing JModelAdmin, and making all of my models inherit from my new base admin model. Within this class, I override the 'preprocessForm' method that is called by the MVC framework and add the custom fields into the form. It's working great, except I'm curious if there is a better way of doing it.
Here's a snippet from that method. This block of code is looping over all custom fields that are configured for the object. What seems a bit kludgy is how I have to create an XML representation of the fields and then shove them into the form with the ->setField(..) call. It seems that you should be able to use the JField objects and add them to the form.
// this defines how the field will be rendered.
$fieldType = 'inputbox';
$fieldOptions = '';
$fieldFormat = '';
switch ($field->typecode)
{
case 'BIT':
$fieldType = 'radio';
$fieldOptions = '<option value="0">JNO</option><option value="1">JYES</option>';
break;
case 'TEXT':
$fieldType = 'textarea';
break;
case 'DATE':
$fieldType = 'calendar';
break;
case 'DATETIME':
$fieldType = 'calendar';
$fieldFormat = 'format="%Y-%m-%d %H:%M:%S"';
break;
}
$xml = sprintf('<fieldset name="udf"><field type="%s" name="udfId%d" label="%s" description="%s" %s>%s</field></fieldset>'
, $fieldType
, $field->id
, htmlspecialchars($field->code)
, htmlspecialchars($field->description)
, $fieldFormat
, $fieldOptions);
// this assigns the stored UDF data into the data that is bound to the form
$data->{'udfId'.$field->id} = $field->data;
$xmlElement = new SimpleXMLElement($xml);
$form->setField($xmlElement);
On Thursday, 2 August 2012 15:52:24 UTC-7, KHarmer wrote:
I'm intrigued, but confused about what you're asking. Can you explain a bit more?
K...
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/44IvBNM3YcEJ.
To post to this group, send an email to joomla-dev-general@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-general+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.