Differencebetween Readonly="True" & Readonly="Readonly"

What is the difference between readonly= true & readonly= readonly ?

Giving an element the attribute readonly will give that element the readonly status. It doesn't matter what value you put after it or if you put any value after it, it will still see it as readonly. Putting readonly="false" won't work.

Suggested is to use the W3C standard, which is readonly="readonly".

What's the difference between disabled= disabled and readonly= readonly for HTML form input fields?

A readonly element is just not editable, but gets sent when the according form submits. A disabled element isn't editable and isn't sent on submit. Another difference is that readonly elements can be focused (and getting focused when "tabbing" through a form) while disabled elements can't.

Read more about this in this great article or the definition by w3c. To quote the important part:

Key Differences

The Disabled attribute

  • Values for disabled form elements are not passed to the processor method. The W3C calls this a successful element.(This works similar to
    form check boxes that are not checked.)
  • Some browsers may override or provide default styling for disabled form elements. (Gray out or emboss text) Internet Explorer
    5.5 is particularly nasty about this.
  • Disabled form elements do not receive focus.
  • Disabled form elements are skipped in tabbing navigation.

The Read Only Attribute

  • Not all form elements have a readonly attribute. Most notable, the <SELECT> , <OPTION> , and <BUTTON> elements do not have readonly
    attributes (although they both have disabled attributes)
  • Browsers provide no default overridden visual feedback that the form element is read only. (This can be a problem… see below.)
  • Form elements with the readonly attribute set will get passed to the form processor.
  • Read only form elements can receive the focus
  • Read only form elements are included in tabbed navigation.

What is the difference between ReadOnly=true and TextBox1.Attributes.Add( readonly , readonly ) in ASP.NET?

Setting the ReadOnly property to true includes the attribute being set:

if (ReadOnly) {
writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "readonly");
}

However, the property also affects the postback behavior. It will only save the text in the view state when it’s not readonly (original code shortened):

private bool SaveTextViewState {
get {
if (TextMode == TextBoxMode.Password) {
return false;
}
if (Events[EventTextChanged] != null || !IsEnabled || !Visible || (ReadOnly) || this.GetType() != typeof(TextBox)) {
return true;
}
return false;
}
}

And the control also only attempts to restore it when that’s the case:

protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
// …

if (!ReadOnly && !current.Equals(postData, StringComparison.Ordinal)) {
Text = postData;
return true;
}
return false;
}

What's the difference between readOnly=true and TransactionType Never?

The readOnly property tells both Hibernate and your database that you don't want any possible changes to be committed. This sets FlushMode.NEVER in the current Hibernate Session. Even if you call a save() method, no changes will happen in your database.

Propagation.NEVER means that Spring will execute the operation non-transactionally, and will throw an Exception if a transaction exists. This ensures that no transaction will be created.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Propagation.html

What are the benefits to marking a field as `readonly` in C#?

The readonly keyword is used to declare a member variable a constant, but allows the value to be calculated at runtime. This differs from a constant declared with the const modifier, which must have its value set at compile time. Using readonly you can set the value of the field either in the declaration, or in the constructor of the object that the field is a member of.

Also use it if you don't want to have to recompile external DLLs that reference the constant (since it gets replaced at compile time).

How to make a input field readonly with JavaScript?

You can get the input element and then set its readOnly property to true as follows:

document.getElementById('InputFieldID').readOnly = true;

Specifically, this is what you want:

<script type="text/javascript">
function onLoadBody() {
document.getElementById('control_EMAIL').readOnly = true;
}
</script>

Call this onLoadBody() function on body tag like:

<body onload="onLoadBody">

View Demo: jsfiddle.

How to add a “readonly” attribute to an input ?

jQuery <1.9

$('#inputId').attr('readonly', true);

jQuery 1.9+

$('#inputId').prop('readonly', true);

Read more about difference between prop and attr

asp:TextBox ReadOnly=true or Enabled=false?

If a control is disabled it cannot be edited and its content is excluded when the form is submitted.

If a control is readonly it cannot be edited, but its content (if any) is still included with the submission.

jsf inputText only displayed value when is readonly true or outputText

Please see

  • Change inputText value from listener method… and
  • Possible to execute `valueChangeListener` for `p:inputText` without hitting `enter` key?

May I suggest using ajax?
Here is a primefaces example but you could apply to richfaces..

 <h:inputText value="#{facturaBean.stringOne}" >    
<p:ajax event="change" listener="#{facturaBean.processValueChange}" update="strTwo"/> </h:inputText> <h:outputText value="Nombre: " />
<h:inputText id="strTwo" value="#{facturaBean.stringTwo}" />
</h:panelGrid>

private String stringOne= "";
private String stringTwo= "";

public void processValueChange(){
stringTwo = stringOne;
}

With getters etc.. basically on change, fires off to ajax, you do your database call etc, then it returns the response and updates your other input field, it's a much cleaner way than trying to submit forms etc..

Also are you sure you want session scope?

HTML required readonly input in form

I had same requirement as yours and I figured out an easy way to do this.
If you want a "readonly" field to be "required" also (which is not supported by basic HTML), and you feel too lazy to add custom validation, then just make the field read only using jQuery this way:

IMPROVED

form the suggestions in comments

<input type="text" class="readonly" autocomplete="off" required />

<script>
$(".readonly").on('keydown paste focus mousedown', function(e){
if(e.keyCode != 9) // ignore tab
e.preventDefault();
});
</script>

Credits: @Ed Bayiates, @Anton Shchyrov, @appel, @Edhrendal, @Peter Lenjo

ORIGINAL

<input type="text" class="readonly" required />

<script>
$(".readonly").keydown(function(e){
e.preventDefault();
});
</script>


Related Topics



Leave a reply



Submit