field_if_set problems

I am having some issues with #field_if_set.

As I understand it, this is a way to not display a field if it is left blank. If the field is blank, it is NOT supposed to output the beforetext and aftertext.

However, mine is firing the beforetext and aftertext. So what am I doing wrong?

Rhythmyx 6.5.2

Also, as an aside, I noticed that in the documentation, it is referenced as #field_is_set(fieldname, beforetext, aftertext) but in the snippet bin, it builds the field as #field_is_set(beforetext, fieldname, aftertext). The latter appears to be the correct implementation, as I got nothing with the former.

Sean,

The latter is the definition in the system macro file. I have logged an issue to correct the documentation to match the actuial implementation.

RLJII

That’s good to know, but that doesn’t solve my root problem, which is that it doesn’t appear to be working correctly. For the page that does not have that field filled out, it still puts the beforetext and aftertext.

Yes, I’m getting the same thing. Of course, Ephox likes to add code to Edit Live fields, so technically it may be filled out and not blank.

OK, I got it sorted.

The current field_if_set does not work with EditLive fields, since as mdmcginn noted, the editor adds code even if the field is not touched. As such, the field is never blank, so field_if_set always fires.

The solution I came up with was to build a separate field_if_set macro, using the same principle of the displayfield macro, which is basically to strip out everything but text, then check the field. The macro looks like this:


#macro(field_if_set2 $before $field $after)##
    #set($theField = $sys.item.getProperty($field).String)
    #if($theField != "")
        $before##
        #field($field)##
        $after##
    #else##
        #__handlefieldaa($field)##
    #end##
#end

Add this to the rx_resources/vm/rx_assembly.vm file

I am fairly new to Rhythmyx, so I don’t know if this is the cleanest implementation, but hopefully it will help some folks.

I found a bug describing similar behavior that was patched in Version 6.5.1, but I was able to reproduce your behavior in an unpatched 6.5.2 installation. I was not able to reproduce it in an internal build of the latest code being developed for the next release. I’m not sure whether this is a bug that was patched or it is a problem resolved in the latest version of the EditLive DHTML editor.

Either way, Tech Support should be able to help you find a resolution.

RLJII

The behavior of the ephox control was changed recently (but I don’t remember exactly when) for a different, but related reason. Previously, if you had a ‘Required’ validation on an ephox field, it never fired, even though it appeared the field was empty and you had never entered anything. This was due to ‘hidden’ text that was visible in the Code tab. Now, this text is stripped on submission if no data is present. This change would probably resolve the issue noted here.

We have similar problems and I’ve added a line like this to the macro …

#if($theField!="" && $tools.esc.html($theField)!="<p> </p>" && $tools.esc.html($theField)!=" ")

to detect non-breaking spaces and non-breaking spaces within paragraph tags.

And it looks like this because the &nsbp; is encoded as  

Is there a better way to be doing this? It seems very clunky.

I suppose ideally I’m looking for a function that says “if the fields renders to whitespace”

Thanks,
nick.

Look at my last post in this thread. I basically recreated field_if_set with a working version. Been working like a charm.

Yes, your post gave me the idea of modifying this macro.
However, we have fields containing stuff like

(div xmlns:st2=“urn:www.microsoft.com/smarttags2” class=“rxbodyfield” xmlns:st1=“urn:www.microsoft.com/smarttags” xmlns: o=“urn:www.microsoft.com/office” xmlns:x=“urn:www.microsoft.com/excel” xmlns:w=“urn:www.microsoft.com/word”> (/div)

and similar except with § (/p) within the div.

So that’s why I’m trying to test for a few different variations of an empty field. They’re not empty but they render as whitespace on the page. But if I carry on with this approach I’m going to have to test for all possible HTML combinations that render as whitespace.

Hi Nick

The code you mentioned (xmlns:st2=“urn:www.microsoft.com/smarttags2”…) appears in Ephox when users cut and paste directly from Word - Word switches on smart tags by default and it is a real pain. Advising users to use the Paste special -> plain text menu option is one way to ensure that code does not appear but it does rely on users adhering to guidelines.

Is there any way that Rhythmyx could be configured to strip out the Microsoft code automatically in a future release?

Cara

Hi Cara

In your ephox configuration file (/RXRoot/rx_resources/ephox/elj_config.xml) update the following options to clean

<wordImport styleOption="clean"/>
<htmlImport styleOption="clean"/>

This will strip out any non html tags and attributes.

Cheers
James

Hi

Thanks for the code, but it is already in our Ephox config files… we are not getting the “xmlns:st2” namespace errors any more but some Word formatting still shows up on occasion, along with some "<designstimesp…> code which we blame on users pasting directly into Ephox!

Cara

Hi Cara

Can you post some examples of the code using the wrap html button?

Cheers
James

This behavior has been logged as a bug for Rx 6.5.2 and is scheduled to be addressed in a future version of the product. The workaround for the time being is posted below.

Thanks!

  1. In the workbench, go to the System Design tab > Configurations >
    double-click on User Velocity Macros. This will open the rx_assembly.vm
    file.

  2. Add the following code to a new line

    #macro(field_if_set_user $before $field $after)##
    #if($sys.item.hasProperty($field) && ($sys.ltActiveAssembly || $sys.activeAssembly || $sys.item.getProperty($field).getString().trim() !=""))##
    $before##
    #field($field)##
    $after##
    #end##
    #end

  3. Save the file.

  4. Edit your template and replace the macro field_if_set with
    field_if_set_user.

  5. Save your template and test.