s22_tech Moderator Lähettäjä United States Jäsen alkaen lokak. 2019 s22_tech 5 jouluk. 2022 22:04 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 Lähettäjä Sweden Jäsen alkaen toukok. 2013 tim 6 jouluk. 2022 03:21 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 Lähettäjä United States Jäsen alkaen lokak. 2019 s22_tech 6 jouluk. 2022 04:35 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 Lähettäjä Sweden Jäsen alkaen toukok. 2013 tim 6 jouluk. 2022 18:25 I think a placeholder could be just as useful as readonly or custom html.
s22_tech Moderator Lähettäjä United States Jäsen alkaen lokak. 2019 s22_tech 6 jouluk. 2022 19:38 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 Lähettäjä Sweden Jäsen alkaen toukok. 2013 tim 6 jouluk. 2022 21:47 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 Lähettäjä United States Jäsen alkaen lokak. 2019 s22_tech 6 jouluk. 2022 22:34 But how would you insert that into the function parameter of a modules settings() array?
tim Founder Lähettäjä Sweden Jäsen alkaen toukok. 2013 tim 7 jouluk. 2022 03:37 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 Lähettäjä United States Jäsen alkaen lokak. 2019 s22_tech 7 jouluk. 2022 05:02 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 Lähettäjä Sweden Jäsen alkaen toukok. 2013 tim 7 jouluk. 2022 16:23 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 Lähettäjä United States Jäsen alkaen lokak. 2019 s22_tech 7 jouluk. 2022 16:49 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 Lähettäjä Sweden Jäsen alkaen toukok. 2013 tim 7 jouluk. 2022 17:52 My thinking is I would do one to rule them all. ;b