How can I increase the text field length?

How can I increase the text field length?

by Carlos Morales Socorro -
Number of replies: 11
Hello, I'm using a moodle database and I need to increase the text fields length in the template. How can I do it? It's too short and it makes writing a little bit "dirty".

Attachment Pantallazo-3.png
Average of ratings: -
In reply to Carlos Morales Socorro

Re: How can I increase the text field length?

by Robert Brenstein -
You are probably using the WYSIWYG mode of the template editor. Switch to the HTML (aka TEXT) mode to have full control (the "<>" button). You can add size and maxlength for <input> as well as width, align, etc parameters for <td> tags in your "add entry" template to align things as you wish. Also, consider using the textarea field. This type is usually more suitable for longer entries.
In reply to Robert Brenstein

Re: How can I increase the text field length?

by David Bogner -
Picture of Core developers Picture of Plugin developers
Hi,

I thought about this possibility too, but as the input-Tag is not created in the template field, you have to use css or javascript to define the maxlength of the input field.
In the template you only have textfield, so you can't define maxlength in the source code.
But you can probably edit the source-code and fill in some javascript, just look what id your input field has (you can temporarily insert the text#id from the left "elements box") name and id are the same for the input field.
fill in some JavaScript like that at the end (replace name and new-size):
<script type="text/javascript">
document.forms[0].element[name].size=new-size;
document.forms[0].element[name].style.width=new-size;
</script>
It didn't work when I tested it. Anyone another idea?

David
In reply to David Bogner

Re: How can I increase the text field length?

by Robert Brenstein -
Oops. You are right. It slipped my mind that the input tag is implicit. Instead of fiddling with Javascript, the field definitions should be simply enhanced to allow entering those parameters, just as it is done for sizing the textarea fields. Surprising that this hasn't been requested so far. Wait, it just was: MDL-13926. Should be trivial to code.
In reply to David Bogner

Re: How can I increase the text field length?

by Petri Asikainen -
I was able to change input field width, after I removed hard coded style="width: 300px;"
from /mod/data/lib.php line 170, inside function display_add_field().
After that I could use css like :

#field_1 {
width: 50px;
}

to specify field widths.

Cheers,

Petri
In reply to Petri Asikainen

Re: How can I increase the text field length?

by sebastian seitz -

Hi,

i use moodle 3.1+ and try to decrease the size of an INPUT textfield.

I had a look in /mod/data/style.css and tried some modifications there, but none of them working.

The hint from Petri Asikainen is good but the display_add_field() function has no style="width: 300px" code. so i think the position of this point has changed in version 3.1+.


any suggestions?

In reply to sebastian seitz

Re: How can I increase the text field length?

by William Lu -
Picture of Particularly helpful Moodlers

Don't change the code, just add CSS or JS into the 'Add template' as below:


Make sure you have clicked on the 'Disable editor' button.

You can find the 'Field ids' in the Available tags' area.

In reply to William Lu

Re: How can I increase the text field length?

by sebastian seitz -

This does not work for me! I will change the size of the INPUT textfield! There is no CSS working or maybe i did not find the right css title.


my css class is .datagrid so i use

.datagrid input {width:50px;}

.datagrid input{height: 500px;} is working but is not needed ;) something for the width is blocking the css code.

to change the size but this is not working.

In reply to sebastian seitz

Re: How can I increase the text field length?

by William Lu -
Picture of Particularly helpful Moodlers
Could you please attach your preset here? I will add the CSS for you.

In reply to William Lu

Re: How can I increase the text field length?

by sebastian seitz -
In reply to sebastian seitz

Re: How can I increase the text field length?

by William Lu -
Picture of Particularly helpful Moodlers

Here you are.


Tips and Tricks:

1. Apply CSS to Table is not enough to change the size of a textfield.

2. Every field needs a <style>

3. The JS method is working as well, you can get the same result.

Average of ratings: Useful (1)