<![CDATA[ ADDITION/UPDATE: Pre-set field value for NewsPublisher - My Forums]]> https://forums.modx.com/thread/?thread=97973 <![CDATA[ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-529804
I've just made a small change to my NewsPublisher snippet that could be of use to somebody - being able to pre-set a field value in the [[!NewsPublisher]] call:

[[!NewsPublisher?
   ...
   &show=`pagetitle,parent,content`
   &required=`pagetitle,parent,content`
   &contentValue=`blah`
   ...
]]


in the relevant field tpl:
<textarea rows="[[+npx.rows]]" cols="[[+npx.cols]]" class="[[+npx.class]] form-control" name="[[+npx.fieldName]]" id="np-[[+npx.fieldName]]">
   [[+np.[[+npx.fieldName]]:default=`[[+np.[[+npx.fieldName]]Value]]`]]
</textarea>


in the snippet (around line 155):
/*set placeholder content values*/
if(isset($scriptProperties['show'])){
    $show = explode(",",$scriptProperties['show']);
    foreach($show as $field){
        if(isset($scriptProperties[''.$field.'Value'])){
            $modx->toPlaceholder(''.$field.'Value', $scriptProperties[''.$field.'Value'], $np_prefix);
        }       
    }
}


Wasn't sure where else to put it - but figured it might be useful...]]>
kctechsoln Aug 10, 2015, 12:12 PM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-529804
<![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-546997

[[+npx.readonly]]


Be sure there is a space on each side of it.]]>
BobRay Dec 06, 2016, 09:15 PM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-546997
<![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-546995
Also, check the &parents property. It affects the opportunity to duplicate a resource.]]>
BobRay Dec 06, 2016, 08:48 PM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-546995
<![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-546792
I Implemented the solution suggested earlier for the pre-set fields which works quite well. So no worries in this aspect.

Caching: This doesn't change the results. Really strange. Anyway, this a minor problem, so I'll leave it with that.

Another thing that is a bit more annoying is that the dublicate button does not work here. While updating and deleting resources from newspublisher works fine, when I press duplicate I get the same address but the page is completely empty (not even the template is loaded). Any idea why?]]>
frischnetz Nov 29, 2016, 12:14 AM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-546792
<![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-546651
On your second question, I'm not sure why that wouldn't work. It might be a caching issue. You might try it like this:

[[!+npx.help:isnot=``:then=`<br>([[+npx.help]])`:else=``]]
]]>
BobRay Nov 23, 2016, 10:39 PM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher?page=2#dis-post-546651
<![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-546623
I'm working on a problem where pre-setting values would save me a ton of workarounds. So before I start hacking the newspublisher package with above patches (and breaking it when updating) I thought I'd ask how the changes are coming around?

Also I noticed that &readonly doesn't seem to work on regular text-fields. I can change and save such fields just fine which is not what I expected.

And in the field-templates (e.g. npTextTpl) I could not use output modifiers for the placeholders: I wanted to do something like:

[[+npx.help:isnot=``:then=`<br>([[+npx.help]])`:else=``]]


But this always returns the else-case, even if [[+npx.help]] is not empty. Why is that? I even tried a similar thing with the If-snippet, which gives the same results.

Jörg]]>
frischnetz Nov 23, 2016, 02:50 AM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-546623
<![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-543560
&presets=`pagetitle:SomeTitle,&mytv:Some Other Value,usernametv:[[!+modx.user.id:userinfo=`fullname`]]`


One suggestion on your code -- this will throw a PHP E_NOTICE error it the *_value property is not set:

$presetValue = $this->props[$name . '_value'];


I'd suggest changing it to something like:

$presetValue = $this->modx->getOption($name . '_value', $this->props, false, true);


That will set it to false if the property is missing or empty, so the rest of your code should work fine.]]>
BobRay Jul 25, 2016, 11:51 PM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-543560
<![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-543549 Yes you are correct, I did not notice that because I was not using any of the standard resource fields in my form. Also, I noticed with the way I set it up, the TVs were not showing their default value.
So my new solution was to not use the code that kctechsoln provided but just to modify the newspublisher.class.php in a couple of places. First I replaced my change above and replaced it with this (line 1213):
if (!$this->existing) {
$presetValue = $this->props[$name . '_value'];
if ($presetValue) {
$this->modx->toPlaceholder($name, $presetValue, $this->prefix );
} else {
$this->modx->toPlaceholder($name, $ph, $this->prefix );
}
} else {
$this->modx->toPlaceholder($name, $ph, $this->prefix );
}


I also changed the displaySimple function (line 1527) by adding the same above code in order to make the pre-setting of the standard resource fields work:
protected function _displaySimple($name, $tplName, $maxLength = 10) {
if (!$this->existing) {
$presetValue = $this->props[$name . '_value'];
if ($presetValue) {
$this->modx->toPlaceholder($name, $presetValue, $this->prefix );
} else {
$this->modx->toPlaceholder($name, $ph, $this->prefix );
}
} else {
$this->modx->toPlaceholder($name, $ph, $this->prefix );
}
$PHs = array('[[+npx.maxlength]]' => $maxLength);
return $this->strReplaceAssoc($PHs, $this->getTpl($tplName));
}


Now it only adds the pre-set value when creating the form for a new resource. Also, I made my Newspublisher snippet properties slightly different then kctechsoln, instead of "Value" added after the field name I am using "_value" like so:
[[!NewsPublisher?
   ...
   &show=`pagetitle,mytv,usernametv`
   &pagetitle_value=`Pre-set Page Title`
   &mytv_value=`Pre-set Template Variable Value`
   &usernametv_value=`[[!+modx.user.id:userinfo=`fullname`]]`
   ...
]]


Hopefully this might help someone else and thank you Bob.]]>
artstewweb Jul 25, 2016, 04:36 PM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-543549
<![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-543512 BobRay Jul 22, 2016, 11:30 PM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-543512 <![CDATA[Re: ADDITION/UPDATE: Pre-set field value for NewsPublisher]]> https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-543496 The version I modified is 2.1.0-pl and yes you are correct the change I made was only for the TVs. Pre-setting the regular fields already worked for both new and existing documents using kctechsoln method. So for me a fix was not needed for those fields. Thanks.]]> artstewweb Jul 22, 2016, 08:33 AM https://forums.modx.com/thread/97973/addition-update-pre-set-field-value-for-newspublisher#dis-post-543496