How to disable or make it read only for input fields

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
wplim
Veteran Member
Posts: 36
Joined: 2013-01-17 22:42

How to disable or make it read only for input fields

Post by wplim » 2014-12-05 20:10

I have seen solutions for making a text input field read only based on the content of a field using hook file "tablename-dv.js"

Code: Select all

if(document.getElementById("fieldname1").value!=""){
document.getElementById("fieldname2").readOnly = true;
}
How about other field types supported by appgini such as Date, checkbox, dropdown, and radio button?

Thank you.

Weoi

Bertv
Veteran Member
Posts: 65
Joined: 2013-12-11 15:59

Re: How to disable or make it read only for input fields

Post by Bertv » 2014-12-13 14:04

Hi,
I use the following methods:

for a listbox:
// set listbox fieldname_of_listbox to read-only
document.getElementById("fieldname_of_listbox-container").disabled = true;
// set button off
document.getElementById("related_table_name_plink2").hide();
look for the correct number in plink in the elements.

for a date:
// set listbox datefield to read-only
document.getElementById("datefield-dd").disabled = true;
document.getElementById("datefield-mm").disabled = true;
document.getElementById("datefield").disabled = true;
// set calender off
document.getElementById("fd-but-datefield").hide();

for a checkbox:
// set checkbox read-only
document.getElementById("field_name0").disabled = true;
document.getElementById("field_name1").disabled = true;
document.getElementById("field_name2").disabled = true;
Bert
I am using Appgini 5.75

wplim
Veteran Member
Posts: 36
Joined: 2013-01-17 22:42

Re: How to disable or make it read only for input fields

Post by wplim » 2014-12-16 06:50

Thank you!

globaldrip8
Posts: 27
Joined: 2015-12-19 03:59

Re: How to disable or make it read only for input fields

Post by globaldrip8 » 2016-08-20 07:59

What will happen if user make javascript disable on browser?

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: How to disable or make it read only for input fields

Post by grimblefritz » 2016-08-20 12:39

AppGini won't work if javascript is disabled, so there's no additional risk in using javascript in hooks. Besides, I thought the phobias about javascript were dispelled long ago. It's been years since I encountered anyone running with it disabled.

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: How to disable or make it read only for input fields

Post by grimblefritz » 2016-08-20 12:54

I recommend against using disabled fields, unless you don't want to retain the data in those fields.

See this thread: http://forums.appgini.com/phpbb/viewtop ... f=8&t=2159

The method I use, using jquery, is included in that thread. It gives me all the benefits of disabled over readonly, without the data loss risk of disabled.

That thread also includes the jquery for disabling a rich text field.

One advantage of jquery is it can process multiple fields. The following snippet sets 6 fields. It could just as easily set 1 or 100.

Code: Select all

$j(function(){

  // set "disabled" fields

  var fieldlist='#type, #description, #unit, #buy_price, #sell_price, #suggested_price';

  $j(fieldlist).prop('readonly', true);
  $j(fieldlist).prop('tabIndex', -1);
  $j(fieldlist).prop('style', 'cursor: not-allowed; background-color: #EEE;');
  $j(fieldlist).mousedown(function(){return false;});

});

globaldrip8
Posts: 27
Joined: 2015-12-19 03:59

Re: How to disable or make it read only for input fields

Post by globaldrip8 » 2016-08-27 16:55

grimblefritz wrote:I recommend against using disabled fields, unless you don't want to retain the data in those fields.

See this thread: http://forums.appgini.com/phpbb/viewtop ... f=8&t=2159

The method I use, using jquery, is included in that thread. It gives me all the benefits of disabled over readonly, without the data loss risk of disabled.

That thread also includes the jquery for disabling a rich text field.

One advantage of jquery is it can process multiple fields. The following snippet sets 6 fields. It could just as easily set 1 or 100.

Code: Select all

$j(function(){

  // set "disabled" fields

  var fieldlist='#type, #description, #unit, #buy_price, #sell_price, #suggested_price';

  $j(fieldlist).prop('readonly', true);
  $j(fieldlist).prop('tabIndex', -1);
  $j(fieldlist).prop('style', 'cursor: not-allowed; background-color: #EEE;');
  $j(fieldlist).mousedown(function(){return false;});

});
thank you very much for answered and solve my question grimblefritz its save tons of my time

globaldrip8
Posts: 27
Joined: 2015-12-19 03:59

Re: How to disable or make it read only for input fields

Post by globaldrip8 » 2016-08-27 17:14

grimblefritz wrote:AppGini won't work if javascript is disabled, so there's no additional risk in using javascript in hooks. Besides, I thought the phobias about javascript were dispelled long ago. It's been years since I encountered anyone running with it disabled.
Just running appgini with disabled javascript and it seems appgini still working

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: How to disable or make it read only for input fields

Post by grimblefritz » 2016-08-27 17:18

There's a lot of stuff in AG that depends on javascript. It might be functioning, but I doubt it's fully functional.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: How to disable or make it read only for input fields

Post by DevGiu » 2016-10-11 15:01

This function "detects" if field it's a select and disable it or use griblefritz system in other (text) situations. It expects an array of fields

Code: Select all

function setFieldAsLabel(array_field_selector){
		var arrayLength = array_field_selector.length;
		for (var i = 0; i < arrayLength; i++) {
			var $field = $j('#'+array_field_selector[i]);
			if ($j('#'+array_field_selector[i]+'-container').length != 0) {
				$j('#'+array_field_selector[i]+'-container').select2('enable', false);
				$j('#'+array_field_selector[i]+'-container').parent().find('button').hide();

			} else {
				$j('#'+array_field_selector[i]).prop('readonly', true);
				$j('#'+array_field_selector[i]).prop('tabIndex', -1);
				$j('#'+array_field_selector[i]).prop('style', 'cursor: not-allowed; background-color: #EEE;');
				$j('#'+array_field_selector[i]).mousedown(function(){return false;});
			}
		}
}
How to use it

Code: Select all

var myfields = ["field1","field2","field3"];

setFieldAsLabel(myfields);
/Giuseppe
Professional Outsourcing Services

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: How to disable or make it read only for input fields

Post by dharbitindy » 2019-07-18 18:15

globaldrip8 wrote:
2016-08-27 16:55
grimblefritz wrote:I recommend against using disabled fields, unless you don't want to retain the data in those fields.

See this thread: http://forums.appgini.com/phpbb/viewtop ... f=8&t=2159

The method I use, using jquery, is included in that thread. It gives me all the benefits of disabled over readonly, without the data loss risk of disabled.

That thread also includes the jquery for disabling a rich text field.

One advantage of jquery is it can process multiple fields. The following snippet sets 6 fields. It could just as easily set 1 or 100.

Code: Select all

$j(function(){

  // set "disabled" fields

  var fieldlist='#type, #description, #unit, #buy_price, #sell_price, #suggested_price';

  $j(fieldlist).prop('readonly', true);
  $j(fieldlist).prop('tabIndex', -1);
  $j(fieldlist).prop('style', 'cursor: not-allowed; background-color: #EEE;');
  $j(fieldlist).mousedown(function(){return false;});

});
thank you very much for answered and solve my question grimblefritz its save tons of my time
Works great, thank you!


Post Reply