Jump to content

Robin S

Members
  • Posts

    4,934
  • Joined

  • Days Won

    321

Everything posted by Robin S

  1. The searchable AsmSelect feature is cool! Just wanted to add: ajax-loaded inputfields (via inputfield visibility setting or repeater item setting) trigger a "reloaded" event on the inputfield to signal when the field is loaded. So you could use this instead of the requestAnimationFrame trick if you want. See InputfieldAsmSelect.js for an example of how this event can be used. $(document).on('reloaded', '.InputfieldAsmSelect, .InputfieldPage', function() { console.log('The AsmSelect inputfield was ajax-loaded'); });
  2. Hi @teppo, Just wondering about updating to the v2 branch on a project I have under development. In the quote above, do you mean that the range of fieldtypes supported on the v2 branch is currently narrower than the v1 branch (only text and file/image fields)? Or do you expect that all the fieldtypes supported in v1 (integer, datetime, etc) will also work in v2 branch but just that you haven't tested them yet? If it's the latter I will probably go ahead and upgrade (unless you think that wouldn't be wise to do yet).
  3. Check to make sure you don't have HTML Entity Encoder selected as a text formatter for the field. I just tried installing the Codemirror plugin for CKEditor and it's working as expected here (although I did need to select a light-coloured theme because the extra specificity coming from editor.css forced the text to black).
  4. You can use $pageimages->add() to add images to a field. $page->image_field->add('/full/path/to/image.jpg'); ...or... $page->image_field->add('http://domain.com/url/to/image.jpg'); But seeing as you will probably want to replace the existing image while keeping the same name you might want to use the PW admin to drop the new image onto the existing one. Not sure if there is an equivalent for doing that via the API.
  5. It's not sRGB. Perhaps consider setting up a batch process in Photoshop to convert your supplied images to sRGB profile. Setting individual imageSizerOptions in config like that doesn't work. There are two options for overriding individual options in /site/config.php... $config->imageSizerOptions = array_merge($config->imageSizerOptions, ['upscaling' => false]); ...or... $config->imageSizerOptions('upscaling', false);
  6. Besides the validation inside InputfieldPage there is also validation done by the specific inputfield type used in the field (e.g. AsmSelect, SelectMultiple, etc). I forgot about this. Many of these extend InputfieldSelect and so use the processInput method there. So whatever pages you are showing in the Page Reference field have to be one of the $options for that inputfield (e.g. see InputfieldSelect::isOption method). So I think your problem is coming from this part... Whatever pages you restrict to here are the only ones that will pass validation. So rather that limiting the options with this hook you might need to come up with other strategy for hiding the options. For example, hide unwanted options with JS, or trigger a change on the source Page Reference field on load so your dependent select kicks in right from the start.
  7. Yes it does, thanks. Silly me, I had the Debug panel open from the standard (non-AJAX) bar and for some reason was imagining it might update in real time. I didn't think to check the AJAX bar.
  8. There is validation done in InputfieldPage::isValidPage - this is done using whatever settings you have defined for the selectable pages in the Page Reference field settings. So you would want to make sure whatever settings you have there are broad enough to allow for any of the pages you are showing in the inputfield via your hooks. If the settings need to be so broad that a very large number of pages would be matched then you might want to consider making the hook to ProcessPageSearch::executeFor a "replace" hook so the method isn't needlessly returning a huge number of pages before you replace its return value. Likewise consider replacing InputfieldPage::getSelectablePages for the field.
  9. Solved! if($foo instanceof Page) $foo = $foo->and(); Nice and tidy.
  10. Hi @adrian, Is there a way to see actions executed in the Console and Snippets panels reflected in the Debug panel? So if in the Console panel I execute some code that gets data from the database, is there a way I can I see PDO Queries, Selector Queries, Hooks Triggered, etc, for that?
  11. If I have a variable that might be a Page or a PageArray, is there an elegant way to standardise to a PageArray? In other words, if $foo is a Page convert it to a PageArray containing just that one page while keeping the variable name. I know how to do it in several steps, but I feel like I've seen a nice one-liner somewhere, maybe in a module by @adrian or @kongondo?
  12. Inputfield::renderReady was made hookable as Inputfield::renderReadyHook in PW 3.0.44. So the module could be updated to hook after InputfieldPage::renderReadyHook instead of before InputfieldPage::render - then it will work with repeater fields. That would add a requirement of PW >= 3.0.44, or else the module could check the PW version and hook different methods depending on the version.
  13. The issue is that PW's .htaccess file contains mod_rewrite rules that get executed before any mod_alias redirects. This article explains: So that advice applies here - it's better to do redirects using mod_rewrite so that you can use the [L] flag to prevent other rewrite rules affecting the redirect.
  14. I understand a little better now, but your usage is not how view permissions are intended to be used. Suppose you had a different setup for storing a user's date of birth: a text field for day and month, and a text field for year. I'm not suggesting that you do this - it's just to illustrate how view permissions typically work. In this alternative setup you might apply view permissions for the year field - so it would or wouldn't be viewable depending on role. But in your setup the "hide_year_of_birth" field is not a field that it is useful to limit the viewing of, because it only holds a 1 or a zero and not the actual value you want to hide (the year of birth). Hiding the checkbox field just confuses things IMHO, and would cause problems if any of the users with view restrictions need to edit the "hide_year_of_birth" field in their own profile (you can't edit a field that you can't view). I think instead you should create a new custom permission "view_year_of_birth" and apply it to the relevant roles. Then check for that permission (and the "hide_year_of_birth" value) to determine how the date field should be formatted.
  15. Checkbox Reversed Modifies InputfieldCheckbox so that it shows the reverse of its true value. The checkbox will be unchecked when the field value is 1 and checked when the field value is not 1. Background The core FieldtypeCheckbox does not have a setting that allows a checkbox to be checked by default. One reason for this is that only a checked field saves a value to the database. An unchecked field does not save "0" to the database, but rather does not save any value for the field at all. Therefore there is no way to distinguish between a new field that has not yet been saved (and therefore could potentially get a default checked state) and a field that has deliberately been saved as unchecked. Because of this you sometimes have to use a checkbox in the opposite way than you would like. Suppose your client has requested a checkbox labelled "Bootylicious" that will be checked by default. This isn't possible with FieldtypeCheckbox so instead you have to convince them that a checkbox labelled "Not bootylicious" that is unchecked by default is just as good. This alternative will achieve the same thing, but it's not ideal. A solution This module doesn't change the limitations of the core checkbox field, but it provides a workaround that allows you to show the checkbox with the desired default state and label. So in the example above you would still name the field "not_bootylicious" (otherwise it could get confusing in your template files) but you can label the field "Bootylicious" and the checkbox will appear checked when its true value is actually unchecked, and vice versa. This allows new pages to show the checkbox checked by default. Clear as mud? Usage Install the Checkbox Reversed module. For any Checkbox field where you want the inputfield to show the reverse of its true value, activate the "Reverse the checked state of this inputfield?" option in the field settings. https://github.com/Toutouwai/CheckboxReversed http://modules.processwire.com/modules/checkbox-reversed/
  16. Not sure I understand exactly what you're asking, but InputfieldSelect (and other related inputfields such as AsmSelect) has the addOption() method. So if you wanted your selectable options to be derived from all the pages using the basic-page template you could do this: $basic_pages = $this->pages->find("template=basic-page"); foreach($basic_pages as $basic_page) { // Page ID is value, page title is label $field->addOption($basic_page->id, $basic_page->title); }
  17. On the topic of searchability of encrypted fields, as long as the number of encrypted pages you want to search across is not too huge you can load the pages to a PageArray and then search the PageArray. Using the auto-join tip mentioned recently here by @thetuningspoon... $decrypted = $pages->find("template=some_template", ['loadOptions' => ['joinFields' => ['encrypted_field_name']]]); $items = $decrypted->find("encrypted_field_name%=foo");
  18. This is brilliant! Definitely deserves its own thread in the modules sub-forum. I only tested it briefly so far but I'm amazed at how fast it is - I thought the decryption would cause a noticeable delay.
  19. You can set more advanced labels in a Page Reference field by using a hook. Not sure if there's a better way but here's how I do it. In your Page Reference field settings, choose "Custom format" for the "Label field" setting, and in the "Custom page label format" enter anything you want so long as it is unique to that field, e.g. pwrocks Then in /site/ready.php $wire->addHookAfter('Page::getMarkup', function(HookEvent $event) { $page = $event->object; // Each page that appears in the Page Reference field $key = $event->arguments(0); if($key !== 'pwrocks') return; // the label format specified for the Page Reference field // Now build whatever string you want to show using $page, $page->getForPage(), etc $string = 'Your string here'; $event->return = $string; });
  20. Not saying it wouldn't be a nice feature to add, but if you know the start of the option you are looking for you can find an option in a standard select by just typing into the select box. On Windows anyway.
  21. You can sort them in a saveReady hook. In /site/ready.php: $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); // If the page has the relevant template... if($page->template == 'exhibition') { // Sort the Page Reference field by title $page->works_id->sort('title') ; } }); This of course prevents you from applying a manual sort to the field, and does affect the sort order of the field value when you get it in your template. But it sounds like you are specifying a different sort (chronological) there anyway so that won't be an issue.
  22. I rushed over the the PW repo, all geared up to star... oh, I already did that. Wish I could star it twice.
×
×
  • Create New...