React Native Gifted Chat: Hide other user's avatar - react-native-gifted-chat

Is there a way to hide the other user's avatar too for react native gifted chat? I know you can hide the current user's avatar but I can't find it for the other user.

You can rewrite the Avatar component which will return null, in renderAvatar property.
For example:
<CustomGiftedChat
messages={messages}
renderAvatar={() => null}
onSend={this.onSend}
user={{
_id: 1,
}}
/>

Related

How to clear an image field in django forms?

So my views look like this:
class PostCreateView(CreateView):
model = Post
fields = ['title','content','image', 'status']
The image field currently looks like this:
Is there a way to have like a button to clear the image from the field? The only way to remove the image is to do it from django admin page.
your html file add a button with an id:
<button id="clear">Clear image </button>
Then in your html, add
{% load static %}
<script>
document.getElementById("clear").addEventListener("click", function () {
document.getElementById("image").value = "";
}, false);
</script>
Note that you need to use your chrome developor tool to find out what is the id of your file input field, in the above example, I used "image", but it most likely be different. You need to change get.ElementById("image") with the id of your file input field.

ActiveAdmin specify filter form url

I am using active-admin(AA, 1.0.0) in a rails 4.2 app. I am displaying a list of online users. I have to display a list of users with scopes for each type of user and filters as per the User model fields. Also, I need to display a list of online users on another page.
User(dropdown)
=> Accounts
=> Online Users
To display the users list, i have
ActiveAdmin.register User, as: 'User' do
menu :parent => "Users", :label => "Accounts"
...
end
To display the online users list, i have
ActiveAdmin.register User, as: 'Online User' do
menu parent: "Users", label: "Online Users", url: '/admin/online_users'
actions :index
filter :id
filter :name
filter :email
...
end
Now,the filters are getting displayed properly on the "Online Users" page, but when the filter form is submitted, its submitted to "/admin/users" rather than to "/admin/online_users". Can I pass the url to the filter form? If not, what is the right solution to this problem.
Thanks.
You can redefine the collection_path method which is used by the filter form builder like this:
controller do
def collection_path
admin_online_users_path
end
end

Django form with label directly in the Field, but disappear on typing

I would like to achieve the same effect as google login page that the Label of the text field is shown in the field itself. When any characters is typed in the filed, the label automatically disappeared.
I know how to achieve similar effect with html + java script, like:
<input type="text" name="" id="" value="Email" class="gray" onclick="if(this.value=='Email')
{this.value='';this.className='black'}" onblur="if(this.value=='')
{this.value='Email';this.className='gray'}" />
But could django form does the same effect? I know I can specify initial in the CharField, but it won't disappear on typing.
forms.CharField(max_length=100, label=_("Email"), initial='xxx')
There is a html5 prop called placeholdertext. Here is a Blogpost about how to use it with django forms. Django HTML5 input placeholders
Excerpt:
class MyForm(Form):
name = forms.CharField(widget=forms.TextInput({ "placeholder": "Joe Recruiter" }))

django image upload help

I have a template where the user can input data about himself, and upload his photo. Photo uploading will be done using ajax, with a separate upload button inside the form. My question is how do I upload the photo (when the user clicks on the upload button) and then save the user info when the user clicks on the submit button.
The model looks like this:
class User(models.Model):
name = models.CharField(max_length=50)
# some other fields
image = models.ImageField(upload_to="assets/images")
Thanks!
You could return the id of the User instance you used to save the picture as part of your js callback/success function, use it to populate a hidden field, and then call that user instance and save the rest of the info when the user submits the form.
The bigger question is, especially given that the user is going to submit the form anyway, why do you want to save just the image first?
You would need to use an <input type="button" /> with a JavaScript event handler to process the upload. jQuery's $.POST can do this very easily for you.
If you use an <input type="submit" /> for the image upload, it will also submit its containing form.
You will probably want to disable the actual "save" button until the ajax process has finished and that record has been saved, in case you need to make any associations to other data from your form, etc.
Hope that gets you going.

Django fields in django-registration

I am setting up django registration, and I came across this piece of code in the RegistrationForm --
attrs_dict = { 'class': 'required' }
email = forms.EmailField(widget=forms.TextInput
(attrs=dict(attrs_dict, maxlength=75)),
label='Email')
What does the part (attrs=dict(attrs_dict, maxlength=75)) mean/do? I know what the maxlength part does but was unclear what the creation of a dictionary is doing, and what the attrs_dict is doing. Any explanation of this piece of code would be great. Thank you.
A bit of test showed that dict(attr_dict, maxlenght=75) equals to
{'class': 'required', 'maxlength':75}
So when the email filed is rendered to an html element, 2 attributes, class and maxlength will be added to the label.
It is creating a dictionary of attributes which will be required to add validation kind of things in finally rendered form, in this way we dont need to do anything in the template code to add validation and security.
Each form field in django uses a widget. You can either specify it during field creation or a default widget is used.
Here you are specifying widget TextInput on EmailField
(attrs=dict(attrs_dict, maxlength=75)) becomes:
{'class': 'required', 'maxlength':75}
Now these will be present as attributes in the rendered html for this widget. So, rendered html for field email would look like:
<input id="id_email" type="text" class="required" maxlength="75" name="email" />