Make a filed as readonly

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
shkdxb
Veteran Member
Posts: 40
Joined: 2013-06-28 18:18

Make a filed as readonly

Post by shkdxb » 2014-09-19 06:04

i want to make a primary key field as readonly to prevent any update after initial entry. Appini is allowing to make the readonly all the time. Is it possible to make the field readonly after initial value is entered?

udayvatturi
AppGini Super Hero
AppGini Super Hero
Posts: 85
Joined: 2014-06-14 03:08
Location: India
Contact:

Re: Make a filed as readonly

Post by udayvatturi » 2014-09-22 13:28

Hi,
You better keep the primary key field as auto increment and Readonly,

Or
You can use magic hooks file and disable the field.

shkdxb
Veteran Member
Posts: 40
Joined: 2013-06-28 18:18

Re: Make a filed as readonly

Post by shkdxb » 2014-10-01 16:15

thanks uday. any sample code is appreciated. i would like to use magic hooks
table.field.property== readonly will work?

udayvatturi
AppGini Super Hero
AppGini Super Hero
Posts: 85
Joined: 2014-06-14 03:08
Location: India
Contact:

Re: Make a filed as readonly

Post by udayvatturi » 2014-10-02 17:59

create <tablename>-dv.js file and put in hooks folder

content of file should be

Code: Select all

document.getElementById("<id of the text box>").readOnly = true;

shkdxb
Veteran Member
Posts: 40
Joined: 2013-06-28 18:18

Re: Make a filed as readonly

Post by shkdxb » 2014-10-03 14:59

Sorry its not working, actually i want to make this field to readonly in update mode. the filed name is "Jobnumber".

Code: Select all

document.getElementById("Jobnumber").readOnly = true;
I created a new file MainTable-dv.js (MainTable is table name) in hooks folder and created as above line. but this is not having any effect. what i am doing wrong?

shkdxb
Veteran Member
Posts: 40
Joined: 2013-06-28 18:18

Re: Make a filed as readonly

Post by shkdxb » 2014-10-03 16:02

is it possible to use function MainTable_before_update() to make this field readonly? i have tried "'MainTable'.'Jobnumber'.Disabled = true;" and "'MainTable'.'Jobnumber'.readOnly = true;" but both of them not working

Code: Select all

function MainTable_before_update(&$data, $memberInfo, &$args){
			'MainTable'.'Jobnumber'.Disabled = true;			
		return TRUE;
	}

shkdxb
Veteran Member
Posts: 40
Joined: 2013-06-28 18:18

Re: Make a filed as readonly

Post by shkdxb » 2014-10-03 17:38

Thanks uday done it

Code: Select all

if(document.getElementById("Jobnumber").value!=""){
document.getElementById("Jobnumber").readOnly = true;
}

udayvatturi
AppGini Super Hero
AppGini Super Hero
Posts: 85
Joined: 2014-06-14 03:08
Location: India
Contact:

Re: Make a filed as readonly

Post by udayvatturi » 2014-10-07 02:35

You are welcome :)

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: Make a radio button Read Only after selection

Post by peebee » 2015-07-22 00:03

Following on from this thread, I had the need to make a radio button selection disabled (read only) after the selection was made. Here's what eventually worked for me.

Let's say you have 3 x radio buttons (None, Yes & No). You want the selection to become read-only (disabled) after the selection is made & saved.

Firstly, determine the ID's of the radio buttons that have been created by Appgini (use Firebug or your browser developer tools). The radio buttons are generated in Appgini from a <%%COMBO(radio-field-name)%%> command so it is not obvious to start with.

Then, in YourTableName-dv.js add the following;

(function () {
if (window.addEventListener) {
window.addEventListener('DOMContentLoaded', domReady, false);
} else {
window.attachEvent('onload', domReady);
}
} ());

function domReady() {
if(document.getElementById("yourradioID2").checked){
document.getElementById("yourradioID1").disabled = true;
document.getElementById("yourradioID3").disabled = true;
}
if(document.getElementById("yourradioID3").checked){
document.getElementById("yourradioID1").disabled = true;
document.getElementById("yourradioID2").disabled = true;
}
}

That's it. If "Yes" is selected, then "None" and "No" are now disabled. Likewise if "No" is selected. The DOMContentLoaded function is required as a "null" Javaccript error is returned otherwise.

Hopefully that may prove useful to somebody other than me.

PS: The DOMContentLoaded function is HTML5 and apparently won't work in old Internet Explorer pre Version 8. There are workarounds but not necessary as far as I'm concerned. Works on every other modern browser.

Post Reply