xPages: make Edit box readonly if it has a value

Hi All,

I'm struggling with what I should put in the readonly compute value box to get it to be readonly if it has a value.

Anyone know what it should be?


Many thanks
D
LVL 2
detox1978Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sjef BosmanGroupware ConsultantCommented:
Probably just its value.

It can be done maybe using EL (Expression Language), just write the name if the field.

If not, use a JavaScript expression that gets the field. Any non-zero value yields true when tested (a bit crude, but it works). In JavaScript (Server Side): currentDocument.getItemValueString("fieldName")
0
detox1978Author Commented:
Sorry for the late reply.

I tried writing the name into the computed field as Expression Language, but nothing happened.

Any ideas?
0
Sjef BosmanGroupware ConsultantCommented:
Can you post the source code, please?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

detox1978Author Commented:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
	xmlns:xe="http://www.ibm.com/xsp/coreex">



	<xp:this.data>
		<xp:dominoDocument var="document1" action="editDocument"
			formName="index" documentId="2784046F65B98C2480257C05005616E3">
		</xp:dominoDocument>
	</xp:this.data>

	<xp:scriptBlock id="scriptBlock1">
		<xp:this.value>
			<!-- SET USERNAME AS VAR -->
			var ams_username = "<![CDATA[#{javascript:@Name("[CN]",context.getUser().getDistinguishedName())}]]>";

			<!-- disable input boxes that have a value -->

		</xp:this.value>
	</xp:scriptBlock>

	<xp:image url="/logo.gif" id="image1"
		style="position:absolute;top:10px;right:10px;">
	</xp:image>

	<xp:br></xp:br>
	<xp:table>
		<xp:tr>
			<xp:td style="width:10px"></xp:td>
			<xp:td colspan="6">
				<xp:span style="font-size:24pt">
					<h1>Phone System Training</h1>
				</xp:span>
				<xp:span style="font-size:16pt">
					Please click the time slot you would like to book.
				</xp:span>
				<xp:br></xp:br>
				<xp:br></xp:br>
			</xp:td>
		</xp:tr>
		<xp:tr>
			<xp:td></xp:td>
			<xp:td></xp:td>
			<xp:td>Delegate 1</xp:td>
			<xp:td>Delegate 2</xp:td>
			<xp:td>Delegate 3</xp:td>
			<xp:td>Delegate 4</xp:td>
			<xp:td>Delegate 5</xp:td>
			<xp:td>Delegate 6</xp:td>
		</xp:tr>
		<xp:tr>
			<xp:td></xp:td>
			<xp:td>09:30 - 10:15</xp:td>
			<xp:td>
				<xp:inputText id="inputText1"
					value="#{document1.Untitled}" readonly="true">

					<xp:this.onclick><![CDATA[#{javascript:@Name("[CN]",context.getUser().getDistinguishedName())}]]></xp:this.onclick>
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText2"
					value="#{document1.Untitled_1}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText3"
					value="#{document1.Untitled_2}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText4"
					value="#{document1.Untitled_3}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText5"
					value="#{document1.Untitled_4}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText6"
					value="#{document1.Untitled_5}">
				</xp:inputText>
			</xp:td>
		</xp:tr>
		<xp:tr>
			<xp:td></xp:td>
			<xp:td>10:30 - 11:15</xp:td>
			<xp:td>
				<xp:inputText id="inputText7"
					value="#{document1.Untitled_6}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText8"
					value="#{document1.Untitled_7}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText9"
					value="#{document1.Untitled_8}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText10"
					value="#{document1.Untitled_9}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText11"
					value="#{document1.Untitled_10}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText12"
					value="#{document1.Untitled_11}">
				</xp:inputText>
			</xp:td>
		</xp:tr>
		<xp:tr>
			<xp:td></xp:td>
			<xp:td>11:30 - 12:15</xp:td>
			<xp:td>
				<xp:inputText id="inputText13"
					value="#{document1.Untitled_12}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText14"
					value="#{document1.Untitled_13}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText15"
					value="#{document1.Untitled_14}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText16"
					value="#{document1.Untitled_15}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText18"
					value="#{document1.Untitled_16}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText19"
					value="#{document1.Untitled_17}">
				</xp:inputText>
			</xp:td>
		</xp:tr>
		<xp:tr>
			<xp:td></xp:td>
			<xp:td>13:00 - 13:45</xp:td>
			<xp:td>
				<xp:inputText id="inputText20"
					value="#{document1.Untitled_18}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText21"
					value="#{document1.Untitled_19}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText22"
					value="#{document1.Untitled_20}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText17"
					value="#{document1.Untitled_21}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText23"
					value="#{document1.Untitled_22}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText25"
					value="#{document1.Untitled_23}">
				</xp:inputText>
			</xp:td>
		</xp:tr>
		<xp:tr>
			<xp:td></xp:td>
			<xp:td>14:00 - 14:45</xp:td>
			<xp:td>
				<xp:inputText id="inputText26"
					value="#{document1.Untitled_24}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText27"
					value="#{document1.Untitled_25}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText28"
					value="#{document1.Untitled_26}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText24"
					value="#{document1.Untitled_27}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText29"
					value="#{document1.Untitled_28}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText30"
					value="#{document1.Untitled_29}">
				</xp:inputText>
			</xp:td>
		</xp:tr>
		<xp:tr>
			<xp:td></xp:td>
			<xp:td>15:00 - 15:45</xp:td>
			<xp:td>
				<xp:inputText id="inputText31"
					value="#{document1.Untitled_30}" readonly="#{inputText31}">
					<xp:eventHandler event="onclick" submit="true"
						refreshMode="complete">
						<xp:this.action>
							<xp:modifyField name="Untitled_30"
								var="document1">
								<xp:this.value><![CDATA[#{javascript:@Name("[CN]",session.getEffectiveUserName())}]]></xp:this.value>
							</xp:modifyField>
						</xp:this.action>
					</xp:eventHandler>
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText32"
					value="#{document1.Untitled_31}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText33"
					value="#{document1.Untitled_32}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText34"
					value="#{document1.Untitled_33}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText35"
					value="#{document1.Untitled_34}">
				</xp:inputText>
			</xp:td>
			<xp:td>
				<xp:inputText id="inputText36"
					value="#{document1.Untitled_35}">
				</xp:inputText>
			</xp:td>
		</xp:tr>
	</xp:table>
	<xp:button value="save" id="save">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="complete">
			<xp:this.action>

				<xp:actionGroup>
					<xp:actionGroup>
						<xp:saveDocument var="document1"></xp:saveDocument>
					</xp:actionGroup>
					<xp:confirm
						message="Thank you!  Your place has been saved.">
					</xp:confirm>
				</xp:actionGroup>
			</xp:this.action>
		</xp:eventHandler>
	</xp:button>
</xp:view>

Open in new window

0
Sjef BosmanGroupware ConsultantCommented:
I assume it's line 59 that doesn't work. If you want the click to assign a value to the field, you have to do that, but in client-side JavaScript: get the field, then assign a value.

The JavaScript code could be:

document.getElementById("#{id:inputText1}").value= "#{javascript:@Name("[CN]",context.getUser().getDistinguishedName())}";

Not quite sure, but I think that in this case

this.value= "#{javascript:@Name("[CN]",context.getUser().getDistinguishedName())}";

works as well, because this refers to the inputText element in the browser.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
detox1978Author Commented:
What should the line look like?

This returned an error (red x in Notes) to indicate it's not valid code.
<xp:this.readonly><![CDATA[#{javascript:this.value= "#{javascript:@Name("[CN]",context.getUser().getDistinguishedName())}";}]]></xp:this.readonly>

Open in new window

0
Sjef BosmanGroupware ConsultantCommented:
this.readonly should yield true or false using Server-Side JavaScript. It should not be used for client-side computations. When exactly should the field become read-only?
0
detox1978Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for detox1978's comment #a39582546

for the following reason:

Thanks
0
detox1978Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.