tires Posted April 2, 2015 Share Posted April 2, 2015 Good evening. Is there a way to preset a value for a field (textarea). This value shold be printet if there isn't anything entered in the field? Thanks an regards! Link to comment Share on other sites More sharing options...
Macrura Posted April 3, 2015 Share Posted April 3, 2015 for the admin you would need to create a module that would check that field, possibly on the buildForm hook; another possibility would be to use AdminCustomFiles and see if there is a way to check the field for empty using JS and then set the value.. but could be risky with JS... Link to comment Share on other sites More sharing options...
nickie Posted April 3, 2015 Share Posted April 3, 2015 I would use some JS code that would add "placeholder" content to the inputfield elements (which would be easy, since they are all referenced by ID in the admin template) wherever I want default content. This way it would only be displayed if the field were empty, and shouldn't be particularly problematic from a security point of view either (I think...). Let me know if you want to see some example code. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 3, 2015 Share Posted April 3, 2015 (edited) You could hook into ProcessPageEdit::loadPage and set the wanted fields. class EmptyFields extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Empty Fields', 'version' => 1, 'summary' => 'Set default title if empty.', 'singular' => true, 'autoload' => 'template=admin', ); } public function init() { $this->addHookAfter('ProcessPageEdit::loadPage', $this, 'afterLoadPage'); } public function afterLoadPage(HookEvent $event) { /* Here you could make your own logic. I've done this ones with a table field. fields in the table were: template-name, field-name and value. Then you can get the right value for your page on the row where template and field-name match. */ $page = $event->return; $page->title = $page->title == '' ? date("Y-m-d H:i:s") : $page->title; } } Edited April 3, 2015 by Martijn Geerts added an example Link to comment Share on other sites More sharing options...
tires Posted April 4, 2015 Author Share Posted April 4, 2015 Thanks for your answers! Ok, i see this is a little complicated and not intended to do for fields in pw. I hoped that there is a possibility to set this preset text/code/file in the fieldsetting (or in the template field settings). Is there a reason not to implement this feature in pw? Link to comment Share on other sites More sharing options...
adrian Posted April 4, 2015 Share Posted April 4, 2015 Some threads worth reading if you haven't already seen them: https://processwire.com/talk/topic/5777-default-value-for-fields-in-admin/ https://processwire.com/talk/topic/1593-how-can-i-specify-default-value-for-certain-input-field/ https://processwire.com/talk/topic/394-default-field-value/ 2 Link to comment Share on other sites More sharing options...
BobbyG66 Posted March 26, 2016 Share Posted March 26, 2016 I came up with a workaround for this. Let me know your thoughts I have an event page set up with a body field to be used for info before the event. (Body_PRE_Event). In the admin pages I created another field (Body_PRE_Event_DEFAULT). I populated this with default text. I then created this php code to see if the event field was filled out, if not, it uses the default field. <?php if ($page->Body_PRE_Event){ echo "{$page->Body_PRE_Event}"; } else{ echo $pages->get("/site-content/event_page_defaults/")->Body_PRE_Event_DEFAULT; } ?> It seems to work well, only issue is that the default info does not appear when creating the event. Which is fine, as long as the editor knows default info will replace it. Thanks BG66 Link to comment Share on other sites More sharing options...
szabesz Posted March 28, 2016 Share Posted March 28, 2016 It seems to work well, only issue is that the default info does not appear when creating the event.Which is fine, as long as the editor knows default info will replace it. Hi, If I understand the issue correctly, you might want to check out these modules, so that you can show the default: http://modules.processwire.com/modules/template-notes/ http://modules.processwire.com/modules/fieldtype-runtime-markup/ http://modules.processwire.com/modules/inputfield-textarea-markup/ Link to comment Share on other sites More sharing options...
tires Posted April 8, 2021 Author Share Posted April 8, 2021 Hi Folks! After a few years went by, i still ask myself if there is an easy way to set a default text/values for text/textarea fields? What do you think? Or am i the only one who needs something like that? 1 Link to comment Share on other sites More sharing options...
dotnetic Posted January 12, 2023 Share Posted January 12, 2023 On 4/8/2021 at 6:55 PM, tires said: After a few years went by, i still ask myself if there is an easy way to set a default text/values for text/textarea fields? I do it with a hook, like described here Link to comment Share on other sites More sharing options...
wbmnfktr Posted January 12, 2023 Share Posted January 12, 2023 @bernhard shows us how to do this with Custom Page Classes here: 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now