Proposal for new form_draw_function type

I'd like to see LiteCart include a "read only" addition to the switch statement in the function form_draw_function() in /includes/functions/func_form.inc.php

case 'readonly':
        return form_draw_text_field($name, $input, 'readonly');
This allows me to show information in a modules settings sections without allowing people to change the value.  Very cool!

Or is this feature already built-in to LiteCart somewhere?
tim
Readonly is not a form type, but a property. I'm thinking a user could want readonly for any form input type?

Maybe a html() function would be more useful?
Whatever you think is better, but what I posted works perfectly for this purpose.  Check out the "Phone Number Format" field in the screenshot.  It's pulling that info from the settings table.  : )
tim
I think a placeholder could be just as useful as readonly or custom html.
But a placeholder doesn't prevent changes in the field - readonly does.  Using readonly makes it obvious that the field isn't modifiable.
tim
Custom HTML is also readonly (unless contenteditable). Here it is in the shape of an input field:
<div class="form-control">Lorem ipsum dolor</div>

That might give the module makers the opportunity to create custom form elements or include links or you name it.
But how would you insert that into the function parameter of a modules settings() array?
tim
Currently the syntax recognized is only for options like radio('this','that'). I would have to rewrite how the passed data is handled. Maybe just make an exception for html('<div class="form-control">Lorem ipsum dolor</div>')?

        [
          'key' => 'foo',
          'default_value' => '',
          'title' => 'Lorem',
          'description' => 'Lorem ipsum',
          'function' => 'html(\'<div class="form-control">Lorem ipsum dolor</div>\')',
        ],

We could also create a new parameter that will override function.

        [
          'key' => 'foo',
          'default_value' => '',
          'title' => 'Lorem',
          'description' => 'Lorem ipsum',
          'html' => '<div class="form-control">Lorem ipsum dolor</div>',
        ],
Whatever you think is best, but I really don't understand what's wrong with what I proposed.  It's short, sweet, and to the point, and the settings section would look like this:
[
 'key' => 'phone_format',
'default_value' => settings::get('phone_format'),
 'title' => language::translate(__CLASS__.':title_phone_format', 'Phone Number Format'),
 'description' => language::translate(__CLASS__.':description_phone_format', 'Set the phone number format in <a href="'. WS_DIR_ADMIN .'?app=settings&amp;doc=format">Settings >> Formatting</a>'),
 'function' => 'readonly()',
],
You wouldn't have to rewrite anything — just add this to function form_draw_function() in /includes/functions/func_form.inc.php
case 'readonly':
        return form_draw_text_field($name, $input, 'readonly');
tim
I really don't understand what's wrong with what I proposed

Not saying it's wrong. Just saying how do I create a readonly textarea? Or readonly datetime?
According to Mozilla, readonly is also usable on textarea and datetime fields:

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly

If that's the case, wouldn't multiple case statements do the trick?

case 'readonly-text':
        return form_draw_text_field($name, $input, 'readonly');

case 'readonly-textarea':
        return form_draw_textarea($name, $input, 'readonly rows="5"');

case 'readonly-datetime':
        return form_draw_datetime($name, $input, 'readonly');
or something like that.
tim
My thinking is I would do one to rule them all. ;b