s22_tech Moderator From United States Member since Oct 2019 s22_tech Dec 5 2022 10:04 PM 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.phpcase '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 Founder From Sweden Member since May 2013 tim Dec 6 2022 03:21 AM 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?
s22_tech Moderator From United States Member since Oct 2019 s22_tech Dec 6 2022 04:35 AM 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 Founder From Sweden Member since May 2013 tim Dec 6 2022 06:25 PM I think a placeholder could be just as useful as readonly or custom html.
s22_tech Moderator From United States Member since Oct 2019 s22_tech Dec 6 2022 07:38 PM But a placeholder doesn't prevent changes in the field - readonly does. Using readonly makes it obvious that the field isn't modifiable.
tim Founder From Sweden Member since May 2013 tim Dec 6 2022 09:47 PM 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.
s22_tech Moderator From United States Member since Oct 2019 s22_tech Dec 6 2022 10:34 PM But how would you insert that into the function parameter of a modules settings() array?
tim Founder From Sweden Member since May 2013 tim Dec 7 2022 03:37 AM 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>', ],
s22_tech Moderator From United States Member since Oct 2019 s22_tech Dec 7 2022 05:02 AM 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&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.phpcase 'readonly': return form_draw_text_field($name, $input, 'readonly');
tim Founder From Sweden Member since May 2013 tim Dec 7 2022 04:23 PM I really don't understand what's wrong with what I proposedNot saying it's wrong. Just saying how do I create a readonly textarea? Or readonly datetime?
s22_tech Moderator From United States Member since Oct 2019 s22_tech Dec 7 2022 04:49 PM According to Mozilla, readonly is also usable on textarea and datetime fields:https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonlyIf 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 Founder From Sweden Member since May 2013 tim Dec 7 2022 05:52 PM My thinking is I would do one to rule them all. ;b