0

I am making a simple form. i am searching any term in django like placeholder, but 'placeholder text' vanishes as user type something in text box. I want something like 'permanent text' in django-text-field, where as user opens the form, they have to start writing something after 'permanent text' which i have entered while coding.

The permanent text should remain there user input and not fade-away like placeholder text does.

1 Answers1

0

Yes, you can. In your form.py you can add all css attribute using widget.

class OrganizationForm(forms.Form):

    class Meta:
        model = Organization
        fields = ('org_about', 'org_pic')

    org_about = forms.CharField(
        label='About Organization',
        required=False,
        widget = forms.Textarea(
            attrs={
                'class': 'form-control valid',
                'onfocus': 'this.placeholder = ''',
                'onblur': "this.placeholder = 'About Your organization'",
                'type':'text',
                'placeholder': 'About Your organization',
                'rows': 5,
                'cols': 15,
                'value': 'about organization',

            }
        )
    )

See more details here about widgets.

There is no way exactly what you want as far as i know. I am sharing an idea you can implement such way:

input {
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="30"><text x="5" y="19" style="font: bold 16px Arial;">Age:</text></svg>') no-repeat;
  border: 1px solid #555;
  box-sizing: border-box;
  font: 16px "Arial";
  height: 30px;
  padding-left: 50px;
  width: 300px;
}
<input type="text" />
more details Besides, you can use :before :after css effect to implement what you want.
Jafoor
  • 695
  • 5
  • 14
  • Thanks for help, but my problem yet not solved, i tried 'value' attrs and it get half work done, that is displaying 'about organization' text in the text box, but it is editable i want text which is fixed rock solid, and cannot be changed. Obviously users can add their text after those fixed words. – Satyam Raj Jul 28 '21 at 13:45