Extensis Logo SUPPORT | FORUMS | KNOWLEDGE BASE

Change separator in multiple value fields


#1

When I try to publish a field with multiple values on ImagePro, the default separator is a comma without even a space. this creates strange looking results like:
Lenon, John,Starr, Ringo,Harrison, George,McCartney, Paul

How can I create something more like this:
Lenon, John ; Starr, Ringo ; Harrison, George ; McCartney, Paul

(please keep in mind that I can only tweak published sites or anything via Netpublish Assistant)


#2

Greetings!

I can show you what that would look like in a published ImagePro site.

In your results.np file, you’ll find a section that looks like this; assume “Beatle” is the name of your field. (I can’t specify what line number you want because it depends on how many fields were selected and what order they’re in.)

<% fieldName = 'Beatle'; %>
<% fieldValue =RecordSet.record.get(unescape('Beatle')); %>
<%   if (fieldValue != "[undefined]" && fieldValue != "") { %>
<strong><%=fieldName%></strong>: 
<% if(fieldName == "Keywords") {%>
<% urlKeywords(fieldValue, "results.np", "mainFrame",Text.UrlKeywordsTitleText);%>
<% }else if(fieldName == "File Size") {%>
<%= Math.round(fieldValue/1024*100)/100 %> MB
<% }else{ %>
<% fieldValue = LocalizeFieldValue(fieldValue); %>
<% checkLength(fieldValue,wrapCharactersAt); %>
<% } %>
<br />

There’s a pair of if statements (an if and an else if, actually) that tell the template file to modify or format the value of the field before inserting it, based on the name of the field.

You can add another else if statement here to add another set of conditions. Here’s an example; I removed some of the extraneous <% %> but the code still works:

<% fieldName = 'Beatle';
fieldValue =RecordSet.record.get(unescape('Beatle'));
if (fieldValue != "[undefined]" && fieldValue != "") {
  Response.write('<strong>' + fieldName + '</strong>:');
  if (fieldName == "Keywords") {
    urlKeywords(fieldValue, "results.np", "mainFrame",Text.UrlKeywordsTitleText);
  } else if (fieldName == "File Size") {
    Response.write(Math.round(fieldValue/1024*100)/100 + " MB");
  } else if (fieldName == "Beatle") {
    Response.write(htmlEncode(LocalizeFieldValue(field.toString().replace(/\b,\b/g, '; '))));
  } else {
    checkLength(LocalizeFieldValue(fieldValue),wrapCharactersAt);
  } %>
<br />

The regular expression I use specifically checks for commas that are between two words but with no space, so it should turn Lennon, John,Starr, Ringo into Lennon, John; Starr, Ringo.

You can do something similar in the detail.np page.


#3

Thank you!!

I’m trying to use this but not able to make it work…

Maybe it will be easier if you could just show me on the original bit of code:

[code]<% fieldName = ‘Artist’; %>
<% fieldValue =RecordSet.record.get(unescape(’*Artist’)); %>
<% if (fieldValue != “[undefined]” && fieldValue != “”) { %>

<strong><%=fieldName%></strong>: 

    <% if(fieldName == "Keywords") {%>
		<% urlKeywords(fieldValue, "results.np", "mainFrame",Text.UrlKeywordsTitleText);%>
	 	<% }else if(fieldName == "File Size") {%>
	 			<%= Math.round(fieldValue/1024*100)/100 %> MB
	 	<% }else{ %>
		<%= htmlEncode(LocalizeFieldValue(fieldValue) ) %>
		<% } %>
<br />
<br />
<% } %>

[/code]


#4

You should be able to take the sample code that I posted and change the references to “Beatle” to “Artist” in the first two lines.

In my sample code, I didn’t add the last
tag and the <% } %> tag that yours has; make sure you don’t delete those in your template or you’ll break it.


#5

Still no luck…
This is the code I’m trying to use, based on the samples above. It doesn’t break but the comma remains as it was:

<% fieldName = 'Artist'; %> <% fieldValue =RecordSet.record.get(unescape('*Artist')); %> <% if (fieldValue != "[undefined]" && fieldValue != "") { %> <strong><%=fieldName%></strong>: <% if(fieldName == "Keywords") {%> <% urlKeywords(fieldValue, "results.np", "mainFrame",Text.UrlKeywordsTitleText);%> <% }else if (fieldName == "File Size") { Response.write(Math.round(fieldValue/1024*100)/100 + " MB"); } else if (fieldName == "*Artist") { Response.write(htmlEncode(LocalizeFieldValue(field.toString().replace(/\b,\b/g, '; ')))); } else{ %> <% fieldValue = LocalizeFieldValue(fieldValue); %> <% checkLength(fieldValue,wrapCharactersAt); %> <% } %> <br />

What am I missing?


#6

Two things:

  1. You have an asterisk in front of “Artist” in the second line
  2. Apparently I did sneak a typo in there:

should be:


#7

Still nothing…
The asterix is actually part of the field name.

Any other Ideas before I give up? Pre-publishing perhaps?

Again, the code I’m using:

[code]<% fieldName = ‘artist’; %>
<% fieldValue =RecordSet.record.get(unescape(’*Artist’)); %>
<% if (fieldValue != “[undefined]” && fieldValue != “”) { %>

<strong><%=fieldName%></strong>: 

    <% if(fieldName == "Keywords") {%>
		<% urlKeywords(fieldValue, "results.np", "mainFrame",Text.UrlKeywordsTitleText);%>
	 	<% } else if (fieldName == "File Size") {
Response.write(Math.round(fieldValue/1024*100)/100 + " MB");

} else if (fieldName == “*Artist”) {
Response.write(htmlEncode(LocalizeFieldValue(field.toString().replace(/\b,\b/g, '; '))));
} else{ %>
<%= htmlEncode(LocalizeFieldValue(fieldValue) ) %>
<% } %>

[/code]

Pity the template builders didn’t think that through:(


#8

In the very first line of your code, you have fieldName defined as ‘artist’, not ‘*Artist’.

That may be why the conditional isn’t picking up your field name.


#9

nsifri3, your code needs 2 edits. firstly, the field name:

As you use ‘fieldname’ later as the check for where to do the extra list value handling, the name here must be the same as you’ll test for later. Thus:

Or, if you want to use ‘artist’ as a screen label for data from the ‘*Artist’ field data, then use a separate declaration & NP variable name:

<% fieldName = '*Artist'; %> <% fieldScreenLabel = 'artist'; %>
Then later use:

Secondly, you also missed Jay’s correction in the line below. ‘field’ should be ‘fieldValue’. Thus:

Becomes: