Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Save fail if Optional Custom Select Field is left empty #8070

Closed
bochos-bln opened this issue Sep 8, 2017 · 8 comments
Closed

User Save fail if Optional Custom Select Field is left empty #8070

bochos-bln opened this issue Sep 8, 2017 · 8 comments

Comments

@bochos-bln
Copy link

Description:

Leave optional (Required false) type select custom Fields empty and Save Users Profile not working.
Show: error-user-registration-custom-field
Not saving Changes
Fill fields would be able to save.

Additional Note Previous Versions needed an empty option also for not required Fields, this seems to be imptoved now. Attached Custom Field COnfig will produce 2 empty fields for Gender. Removing the first empty option will also not solve the Saving Issue.

Server Setup Information:

  • Version of Rocket.Chat Server: 0.59.0-rc.4
  • Operating System: docker, Debian?
  • Deployment Method(snap/docker/tar/etc): docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog: ?
  • Node Version: ?

Steps to Reproduce:

  1. Admin->Registration->Custom Fields add some optional Custom Select fields here is a part of mine:

{
"user_gender": {
"type": "select",
"options": [" ", "female", "male"],
"required": false
},
"phone": {
"type": "text",
"maxLength": 20,
"required": false
},
"description": {
"type": "text",
"required": false
}
}

  1. Changing normal users Profile save with leaving optional field blank result in described error

Expected behavior:

Saving Changes

Actual behavior:

Not Saving Changes

Relevant logs:

No Logs on server

WSS Log
"{"msg":"result","id":"17","error":{"isClientSafe":true,"error":"error-user-registration-custom-field","reason":"Value for field **REMOVED is invalid","details":{"method":"registerUser"},"message":"Value for field **REMOVED is invalid [error-user-registration-custom-field]","errorType":"Meteor.Error"}}

@bochos-bln
Copy link
Author

bochos-bln commented Sep 12, 2017

Additional Information:
Used Docker Compose.yml Setup, just Changed the RocketChat Versions between 0.58.2 (no Bug), 0.59.0-rc.0 (Bug), 0.59.0-rc.4 (Bug)

Its not type Improvement. I would say its type Bug or Release Candidate Bug because using Custom Select Fields worked until 0.58.2 with the Trick to add an empty String as first Selectable Item.

After the Change in 0.59.0-rc.0 (the first Version the Bug appeared) the Profile Setting Form added an empty String as first Option (what is an improvement for the previously used Hack). But not being able to save the Profile without selecting an Option or having 2 empty Select Options if I continue using the previous Hack is not an applicable Solution.

So Please finnisch the Change the right way and allow to save the empty value for Optional Select Fields or remove the auto added empty field to continue the previous Hack.
For Milestone 86 / 0.59.0-rc.5

The Required Validation for Text Fields work fine.

Additionally: there is a Layout Issue in Frontend Profile Settings: Having more then 2 Custom Fields in Desktop View the appeared in one row and the 3rd field have no Padding to the 2nd one.

@Darkneon
Copy link
Contributor

@xlbs-rm Do you have access to the MongoDB? There's a collection name RocketChat_settings with a document _id of Accounts_CustomFields. Can you confirm the options are saved as [" ", "female", "male"] and not as ["", "female", "male"]?

@bochos-bln
Copy link
Author

bochos-bln commented Sep 13, 2017

In 0.59.0-rc.0 the Following Example:

{
"gender": {
"type": "select",
"options": ["female", "male"],
"required": false
},
"field1": {
"type": "select",
"options": [" ", "a", "b"],
"required": false
}
}

Results in:

Short, with Frontend Behaviour Description:
gender Option saved in DB: ["female", "male"]
=> In Frontend there are 3 Options in Dropdown ["", "female", "male"]
=> Try to save the first one Fail, the others succeed
field1 Option saved in DB: [" ", "a", "b"]
=> In Frontend there are 4 Options in Dropdown ["", " ", "female", "male"]
=> Try to save the first one Fail, the others succeed

Original Output:

db.rocketchat_settings.find({"_id": "Accounts_CustomFields"})

{ "_id" : "Accounts_CustomFields", "type" : "code", "public" : true, "i18nLabel" : "Custom_Fields", "group" : "Accounts", "section" : "Registration", "packageValue" : "", "valueSource" : "packageValue", "hidden" : false, "blocked" : false, "sorter" : 31, "i18nDescription" : "Accounts_CustomFields_Description", "ts" : ISODate("2017-09-12T10:27:58.999Z"), "_updatedAt" : ISODate("2017-09-13T07:20:19.898Z"), "createdAt" : ISODate("2017-09-12T10:27:58.998Z"), "value" : "{\n"gender": {\n"type": "select",\n"options": ["female", "male"],\n"required": false\n},\n"field1": {\n"type": "select",\n"options": [" ", "a", "b"],\n"required": false\n}\n}" }

@Darkneon
Copy link
Contributor

@xlbs-rm @MartinSchoeler

I did some digging and it turns out custom fields are treated differently in the registration form (detects old RC) and the profile form (detects new RC). Moreover, the empty value in the new RC is not included in the options on the server side when doing the validation.

@bochos-bln
Copy link
Author

@Darkneon

Confirm that:

  • there are 2 different Forms the Registration and the Profile Form
  • the Content of a Select Dropdown is different Register displays the Field like in Previous RC Versions; in Profile there is an additional empty Option for the example above

I cant say anything about the Server Side Validation because I only use the docker out of the Box Server.

The Bug is still there in 0.59.0-rc.9

There is also UI Layout Bug for more than 3 Custom Fields. They are displayed in one Line / No Line Break.

@Darkneon
Copy link
Contributor

@xlbs-rm That's correct.

@bochos-bln
Copy link
Author

The Bug is still there in 0.60.2:

REST API create a Profile with an
"required": false
Select field fails, if request does not provide a value for this optional custom field

@alinmiron
Copy link

alinmiron commented Jun 27, 2023

The Bug is still there in 0.60.2:

REST API create a Profile with an "required": false Select field fails, if request does not provide a value for this optional custom field

Same in 2023 in version 6.1.5. of Rocketchat

I have the following custom fields
{
"cfType":{
"type":"select",
"options":[
"Doctor",
"Clinic",
"Patient"
],
"required":true,
"private":true,
"public":true
},
"cfDoctorNumer":{
"type":"text",
"minLength":3,
"maxLength":12,
"required":false,
"private":true,
"public":true
},
"cfSpecialization":{
"type":"select",
"options":[
"General medicine",
"Anesthesiology",
"Ophthalmology",
"Surgery",
"Gynecology / Obstetrics",
"Ear, nose and throat medicine",
"Skin-and venereal diseases",
"Internal Medicine",
"Paediatrics",
"Neurology",
"Psychiatry and psychotherapy",
"Radiology",
"Urology",
"Other"
],
"required":false,
"private":true,
"public":true
}
}

I use Rocketchat API to create a new user and I send the following payload:
{ "name":"Alin Miron", "email":"testalin11@mailchimp.com", "password":"tFsNGHST6", "username":"Alin.Miron.mHNs", "active":true, "roles":[ "patient" ], "verified":true, "type":"user", "customFields":{ "cfType":"Patient" } }
No user is created but instead I get this error: Value for field cfSpecialization is invalid [error-user-registration-custom-field]

Later edit: I've even added "defaultValue":"General medicine", for the select but nothing changed

WHY, if I declared the cfSpecialization as optional and also I don't include it in payload I get that error?

WHY, if I don't include customFields object in payload, the user is created in Rocketchat?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants