-
Posts
347 -
Joined
-
Last visited
-
Days Won
4
Peter Falkenberg Brown last won the day on November 28 2019
Peter Falkenberg Brown had the most liked content!
Contact Methods
-
Website URL
https://datavarius.com
Profile Information
-
Gender
Male
-
Location
Maine, USA
-
Interests
I'm a writer, speaker, and publisher.
I also own a web programming consulting business at:
https://datavarius.com
I specialize in creating custom websites and web database applications.
Recent Profile Visitors
Peter Falkenberg Brown's Achievements
-
How to set field focus in ready.php
Peter Falkenberg Brown replied to Peter Falkenberg Brown's topic in API & Templates
Thank you, @kongondo, @bernhard, and @dotnetic! Yes, this is why the PW community ROCKS. I'll test these out soon. Thanks again! Peter -
How to set field focus in ready.php
Peter Falkenberg Brown replied to Peter Falkenberg Brown's topic in API & Templates
Hi @kongondo, This is so cool. Thank you VERY much. It works perfectly. I'm wondering what the best way to load it under certain conditions would be. Right now, it places the cursor in the field whenever I go into edit mode, not just on the initial edit that comes right after adding a record. In my ready.php file I have this: $this->addHookBefore('AdminTheme::getExtraMarkup', function (HookEvent $event) { $config = $this->wire->config; $url = $config->urls->templates; $config->scripts->add($url . "scripts/admin.js"); }); $pages->addHook('added', function(HookEvent $event) { $page = $event->arguments(0); if ( $page->template == 'book_sales' ) { .... etc.... So, in the code that comes after the addHook('added') it only operates in the subsequent edit screen, but not when I go back to a record and click on edit. (At least I don't think so.) Is there a way to only initiate the cursor focus during that initial edit? Thank you again! Peter -
How to set field focus in ready.php
Peter Falkenberg Brown replied to Peter Falkenberg Brown's topic in API & Templates
Thank you, @kongondo! It's a field called "list_price." It's a field of type float. It's in a template called "book_sales." See my ready.php code at the beginning of the thread for what I'm doing with adding values to fields, on a new add record routine. Thanks again for your help! Peter -
How to set field focus in ready.php
Peter Falkenberg Brown replied to Peter Falkenberg Brown's topic in API & Templates
Yes, it should always get the focus when it goes from adding a new record to the edit page of the new record. At other times, it doesn't matter, either way. Any JS gurus want to demonstrate the code and where / how to put it? I'm not a JS person. :-) Thanks! Peter -
How to set field focus in ready.php
Peter Falkenberg Brown replied to Peter Falkenberg Brown's topic in API & Templates
Thanks, @dotnetic and @MarkE... And thanks, @bernhard, in advance. :-) Peter -
How to set field focus in ready.php
Peter Falkenberg Brown replied to Peter Falkenberg Brown's topic in API & Templates
Thanks, @kongondo... In the PW admin, when you click on "New" to add a record, the title field has focus, with the cursor in it. However, when you then hit save and get to the edit page, none of the fields have focus. These pages are part of the built in admin, so I'm wondering if they can be tweaked without editing the core files. Based on your description, it would seem that the New record page must have some type of focus mechanism, either with Javascript or HTML. What are your thoughts? Thanks! Peter -
Hi All, I'm using ready.php to add some values to new pages, so that after I type in the title of the page and hit save, when I get to the edit page of the full set of fields, certain fields have pre-filled values. The routine is working well, but I want to add one more item, to wit: - I want to set the field focus (i.e. the cursor is in that field) to a field called "list_price." Can that be done, in ready.php, and if so, what's the best method? Here's the code I have already: $pages->addHook('added', function(HookEvent $event) { $page = $event->arguments(0); if ( $page->template == 'book_sales' ) { #............................................. $parent = $page->parent(); $parent_path = $parent->path(); $last_item_number_selectors = "parent=$parent_path," . "sort=-item_number," . "$skiptrash," . "limit=1"; $last_item_number = wire("pages")->get("$last_item_number_selectors")->item_number; # the item_number has a 2 letter prefix, followed by 4 digits that have leading zeroes, # and the number has to be incremented, while retaining the leading zeroes. $part1 = substr($last_item_number,0,2); $part2 = substr($last_item_number,2); $part2inc = intval($part2) + 1; $part2new = sprintf('%04d', $part2inc); $new_item_number = $part1 . $part2new; $page->item_number = $new_item_number; #............................................. $admin_now = time(); $page->list_date = wire(datetime)->date($format='Y-m-d', $admin_now); $page->list_year = wire(datetime)->date($format='Y', $admin_now); #............................................. $page->of(false); $page->save(); $page->of(true); } }); Thanks! Peter
-
Thanks, @AndZyk, But adding the single quote marks didn't work. I still get this error message: Fatal Error: Uncaught Error: Call to a member function date() on null in site/ready.php:12 #0 wire/core/WireHooks.php (1050): ProcessWire->{closure}(Object(HookEvent)) #1 wire/core/Wire.php (485): WireHooks->runHooks(Object(Pages), 'saveReady', Array) #2 wire/core/PagesEditor.php (491): Wire->__call('saveReady', Array) #3 wire/core/PagesEditor.php (455): PagesEditor->savePageQuery(Object(Page), Array) #4 wire/core/Pages.php (799): PagesEditor->save(Object(Page), Array) #5 wire/core/Wire.php (420): Pages->___save(Object(Page), Array) #6 wire/core/WireHooks.php (951): Wire->_callMethod('___save', Array) #7 wire/core/Wire.php (485): WireHooks (line 12 of site/ready.php) Peter
-
Hi All, Maybe because my brain is fried tonight, but I'm totally stuck on extracting the 4 digit year from a datetime field inside the ready.php file, on saving a page. Here's my code: $pages->addHook('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if ( $page->template == 'book_sales' ) { if ( $page->sold == 1 ) { $page->profit = ($page->sale_price - $page->buy_cost) - $page->transaction_fee; $page->sale_year = $datetime->date($format='Y', $page->getUnformatted(sale_date)); } } }); The line that tries to get the sale_year, i.e. $page->sale_year = $datetime->date($format='Y', $page->getUnformatted(sale_date)); breaks with a bunch of errors. Anyone have the right syntax? Thanks! Peter
-
Hi @dotnetic, (An aside: I created a spreadsheet that does all of this very quickly. Easy as pie. However, in some cases, a PW database might be better, thus my questions. On the other hand, maybe trying to fit PW with the functionality of spreadsheets is a waste of time. You know... the right tool for the job.) Yes, the PagesSum module is exactly what I need. Thank you! But... in the Admin section, with the standard tree of page types (i.e. templates), assuming that I have a branch of pages called "sales," then where and how could I display the sum of those sales pages (from a field called "sale_price") on the admin page? I haven't adequately dug into the task of modifying the admin page. In a custom app, all based on php template docs, I would simply display that total on the apps version of the "home" page, i.e. like the Admin tree page. But in the PW Admin page, I haven't yet learned how to add a routine to display something like that on the top level admin page. Is there a document somewhere in the PW knowledge base on how to do that? I've already made one small modification to the admin's core files in the wire directory, in a file called "AdminTheme.php." In that file, in the routine public function ___getExtraMarkup() I change this code: if($isLoggedin && $this->wire('config')->advanced) { # $parts['footer'] = "<p class='AdvancedMode'><i class='fa fa-flask'></i> " . $this->_('Advanced Mode') . "</p>"; $parts['footer'] = str_repeat(' ', 10) . "DB: " . wire('config')->dbName . "<br><br>"; } ... so that the admin page would display the name of the database in use (to avoid a dev version using the live db by mistake). ( @ryan Ryan, I think this would be a good addition to the core.) I realize that it's a Bad Idea to modify core files, so in terms of modifications to the admin home/tree page, with the Sum function display, I'm hoping that there's a hook method, or some other way to get that data displayed on the page, without messing with the core files. Thanks! Peter
-
Hi All, I haven't found this answer in the docs or forums. I know how to program a template that would display multi-page field calculations like a spreadsheet, e.g. with 100 pages, each with a dollar value in a field, display the total dollar value of a subset of the 100 pages based on a "sold" data field value. I know how to put that template / url / page behind a password. What I'm not clear about is whether or not PW has an easier method than that. For example, in the standard admin, create a page/template that has the summary fields in it and pull the calculations from the "item" pages whenever the summary page is accessed or a button is pressed. Or something like that. So that the calculations can be viewed in the admin without having to build a password protected, programmed front-end page. Of course, a spreadsheet can do all this easily, but after thousands of records, it becomes rather unwieldy, in my opinion. What do people recommend? Thanks, Peter