What is the process to switch an Editbox from read mode to edit mode in Xpage?

Recently, I tried setting the property Read-Only to true in Xpage for a specific field.

However, when attempting to change its mode to edit using client-side JavaScript, I encountered difficulties. Below is the code snippet I used:

document.getElementById("#{id:read}").readOnly = false;

I also attempted the following:

dojo.attr("#{id:read}", "readOnly", false);

Unfortunately, both approaches failed.

(@Trim)
In addition, the server-side JavaScript XSP code is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" dojoParseOnLoad="true"
dojoTheme="true">
<xp:this.resources>
    <xp:dojoModule name="dijit.Dialog"></xp:dojoModule>
</xp:this.resources>

<div id="dojoTest" dojoType="dijit.Dialog">
<xp:inputText id="field" defaultValue="Hello" readonly="true"></xp:inputText>

<xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="partial" refreshId="field">
        <xp:this.action> <![CDATA[{javascript:getComponent("field").setReadonly(false);}]]></xp:this.action>
    </xp:eventHandler></xp:button>
<xp:br></xp:br></div>

<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Show Popup" id="button2">
    <xp:eventHandler event="onclick" submit="false">
        <xp:this.script><![CDATA[dijit.byId("dojoTest").show();]]> </xp:this.script>
    </xp:eventHandler></xp:button>
</xp:view>

Answer №1

After a thorough investigation, it has been determined that the issue at hand is not related to the field itself. The code provided in the question is indeed suitable for the desired response. The actual problem lies in the fact that the event is defined within a dijit.Dialog.

During the parsing of a dialog in Dojo, the DOM elements are relocated to the end of the body for layout purposes. Regrettably, this action also results in moving them outside of the form. Consequently, any server-side events are disrupted, as the event data is no longer serialized as part of the form. Therefore, in the scenario described, the event does not fail due to incorrect code, but rather because the event itself is not being triggered.

The recommended solution to this issue is to utilize the Dialog component from the Extension Library (or 8.5.3 UP1) rather than a passthru div with a specified dojoType. If this alternative is not feasible, there is a workaround available. You can add the following component at the bottom of the page:

<xp:scriptBlock>
    <xp:this.value><![CDATA[XSP.addOnLoad(function(){
    var dominoForm = XSP.byId("#{javascript:return view.findScriptCollector().getClientId(facesContext);}");
    dojo.query("div.dijitDialog").forEach(function(eachDialog){
        dojo.place(eachDialog, dominoForm, "last");
    });
});]]></xp:this.value>
</xp:scriptBlock>

By implementing this script, all parsed dialogs will be repositioned inside the form, thereby allowing events within them to once again function correctly.

Answer №2

In case you want to implement this functionality on the server side, here is a sample code snippet for a button that toggles between read and edit mode:

var element = getComponent("inputText1");
if (element && !element.isReadonly()) {
    element.setReadonly(true);
}else if (element && element.isReadonly()) {
    element.setReadonly(false);
}

For a comprehensive list of properties for various components that can be accessed via SSJS, refer to this page.

Answer №3

When you generate the field with the code <xp:inputText id="read" readonly="true"></xp:inputText>

it results in a <SPAN Tag being created, which cannot be converted into a text field

<span id="view:_id1:inputText1"></span>

In version 8.5.3, you would access All properties of the field and include an Attribute called READONLY with a value of True

This will generate the following code

<xp:inputText id="read" defaultValue="Marky">
    <xp:this.attrs>
        <xp:attr name="READONLY" value="true"></xp:attr>
    </xp:this.attrs>
</xp:inputText>

If you are using versions prior to R8.5.3, you can dynamically add the READONLY attribute to the field on the onClientLoad event of the page using

dojo.attr("#{id:read}", "READONLY", "true");

Here is the code snippet

<xp:inputText id="read" defaultValue="Marky">

</xp:inputText>

<xp:eventHandler event="onClientLoad" submit="false">
    <xp:this.script><![CDATA[dojo.attr("#{id:read}", "READONLY", "true");]]></xp:this.script>
</xp:eventHandler>

Once you have configured the field correctly on the form, you can enable editing by using

document.getElementById("#{id:read}").removeAttribute('readOnly');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

After a duration of 4 minutes, an ERR_EMPTY_RESPONSE is thrown in response to the

My angular 5 node app involves sending a request to the server and waiting for a response. There are instances where the response takes around 5-6 minutes to arrive. However, an ERR_EMPTY_RESPONSE error is triggered by the http method after just 4 minutes ...

How can you determine if a mouseover event is triggered by a touch on a touchscreen device?

Touchscreen touches on modern browsers trigger mouseover events, sometimes causing unwanted behavior when touch and mouse actions are meant to be separate. Is there a way to differentiate between a "real" mouseover event from a moving cursor and one trigg ...

Setting up vue-apollo 3.0.0 Beta

Seeking guidance as a newcomer in this field. I have experience with Authentication using Apollo client, but I'm stuck when trying to integrate the new vue-apollo-plugin into my Vue-cli-3 generated project. Specifically, I'm confused about how an ...

Expanding size on hover without affecting the alignment of surrounding elements

Imagine there are 10 divs on the page styled as squares, collectively known as the home page. Among these 10: 3 divs belong to the .event1 class, 5 divs belong to the .event2 class, and 2 divs belong to the .event3 class. <div class="boxes event1"> ...

Implementing a Next.js server-side permanent redirection instead of displaying a 404 error page

My Next.js application consists of three routes: /home, /about, and /contact. When a user accesses a route that doesn't exist, Next.js automatically redirects them to the 404 page. However, I want to change this behavior and permanently redirect use ...

Similar to TypeScript's `hasOwnProperty` counterpart

When working with TypeScript objects, is there a way to loop through a dictionary and set properties of another dictionary similar to how it is done in JavaScript? for (let key in dict) { if (obj.hasOwnProperty(key)) { obj[key] = dict[key]; } } If ...

What is the reason for the addEventListener function not being able to access global variables?

I have set up an event listener function to utilize popcorn.js for displaying subtitles. Additionally, I have created functions that are unrelated to popcorn.js outside of the event listener and declared a global variable array. However, when attempting ...

Eliminate redundant tags using jQuery

I have a code snippet that I need help with. I want to check for duplicates and if found, display an alert stating that it already exists so users can't insert the same word/tag again. Can someone please assist me? <div id="tags"> <span>a ...

Enhancing serialized form with additional information through an ajax request

I'm currently facing an issue with adding additional data to my serialized form string. The situation is that I have a form with a set of fields called "Services", and users are able to add as many services as they want dynamically using a button in t ...

Notifying the view with a SignalR message from the controller upon event trigger

Just starting out with SignalR and attempting to set up a notification for a specific event triggered by an API. What I've attempted: Hub: public class NotificationHub : Hub { private static IHubContext hubContext = GlobalHost.Connectio ...

Issue with Webstorm not automatically updating changes made to JavaScript files

On my HTML page, I have included references to several JavaScript files such as: <script type="text/javascript" src="MyClass.js"></script> When debugging in WebStorm using a Python SimpleHTTPServer on Windows with Chrome, I am able to set bre ...

What is the process of converting the timing from my stopwatch to a standard time format?

I am currently working on a stopwatch project where I log the time into an array. However, when I try to use Math.min(array) or Math.max(array), it returns NaN (not a number). The time format for the stopwatch is like 00:00:15.91 which is not recognized as ...

jQuery is used to make an object fade out once another object has been moved into place

As I delve into the world of jQuery, I've decided to create a simple Super Mario imitation. The concept is to control Mario using arrow keys and fade out mushrooms once Mario reaches them. However, my attempts at achieving this result have not been su ...

Error in ng-repeat loop: detecting duplicates when none are present

$scope.subjects = [ "Computer Security", "Graphics and Multimedia", "Networks", "Computer Science and Engineering", "Game Design", "Programming", "Information Technology", "Software Engineering", "Technology Manageme ...

How to dynamically add events to a JQuery FullCalendar using a loop

When utilizing the jQuery full calendar, I need to dynamically set events based on data obtained from a database. To achieve this, I am using data attributes to assign values and then display them on the calendar. Below is an example of my html twig code: ...

Troubleshooting the issue with ajax loadXml callback functionality

My table is empty and I can't figure out where the mistake is. I want to use the console to debug, but I'm not sure how. Update: I found a working sample here http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_xml2. I used similar code, bu ...

Why is AngularJS $http response undefined?

My $http call in AngularJS is returning undefined when I try to access the data in my controller. What could be causing this issue? Despite using .then to handle promises, the data passed to the controller seems to become undefined. Can you help me figure ...

Unable to retrieve elements from the eBay website using JavaScript within a Chrome extension

I recently developed a Chrome extension that scrapes all orders from an eBay orders page. It was working flawlessly last month, but suddenly I am facing issues accessing some elements. Here is the snippet of code causing trouble: let elGridComp = document ...

Determining when props are updated in Vue.js 2 when passing an object as a prop

Let's say there is an array feedsArray, with a sample value like this: this.feedsArray = [ { id: 1, type: 'Comment', value: 'How are you today ?' }, { id: 2, type: 'Meet', name: 'Daily ...

React.js not displaying image

Here's my App.js File I am trying to display an image from the MongoDB database. Click here to view the image stored in MongoDB The images are stored as Binary data in MongoDB How can I display the image on the React page? import React,{useState} fr ...