Page 1 of 1

How to disable or make it read only for input fields

Posted: 2014-12-05 20:10
by wplim
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

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

Posted: 2014-12-13 14:04
by Bertv
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;

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

Posted: 2014-12-16 06:50
by wplim
Thank you!

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

Posted: 2016-08-20 07:59
by globaldrip8
What will happen if user make javascript disable on browser?

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

Posted: 2016-08-20 12:39
by grimblefritz
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.

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

Posted: 2016-08-20 12:54
by grimblefritz
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;});

});

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

Posted: 2016-08-27 16:55
by globaldrip8
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

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

Posted: 2016-08-27 17:14
by globaldrip8
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

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

Posted: 2016-08-27 17:18
by grimblefritz
There's a lot of stuff in AG that depends on javascript. It might be functioning, but I doubt it's fully functional.

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

Posted: 2016-10-11 15:01
by DevGiu
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);

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

Posted: 2019-07-18 18:15
by dharbitindy
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!

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

Posted: 2019-11-18 15:37
by onoehring
Hi,

maybe also check my field permissions posting here: viewtopic.php?f=4&t=3308&p=11438#p11438

Olaf