backbone-forms icon indicating copy to clipboard operation
backbone-forms copied to clipboard

List validation

Open MeterSoft opened this issue 9 years ago • 24 comments

How i can run validation by nested model schema?

schema: { firstName: { type: 'Text', validators: [{ type: 'required', message: 'Can not be blank' }] }, phoneNumbers: { type: 'List', itemType: 'NestedModel', model: infocus.PhoneNumber, title: '' } }

schema: { type: { type: 'Select', options: ['SIP', 'Phone', 'H123'] }, number: { type: 'Text', validators: [{ type: 'required', message: 'Can not be blank' }, { type: 'email', message: 'Invalid number' }] } }

but when i run form.commit() it validate only main model

MeterSoft avatar Jan 12 '16 19:01 MeterSoft

Use master if possible master has support for it, it was added here https://github.com/powmedia/backbone-forms/issues/414

exussum12 avatar Jan 14 '16 21:01 exussum12

It works only if use form.validate() and it return
_others: [[Object { name="firstName", message="Can not be blank"}, Object { name="number", message="Can not be blank"}]]

but if i use form.commit() it validate only main form and return error related this

I have a list of phone numbers but all not have unique id. i think it should add backbone view id and errors should return like this [{"number_view1": "can not be blank"}, {"number_view2": "can not be blank"}] and add this error to own number

Also all list have id like undefined_number

MeterSoft avatar Jan 15 '16 07:01 MeterSoft

Can you give an example ? Im pretty sure i fixed that issue too

exussum12 avatar Jan 16 '16 12:01 exussum12

https://jsfiddle.net/bohdansemenets/zogkbnwe/

MeterSoft avatar Jan 17 '16 12:01 MeterSoft

Can you give that change a go ? Seems to work for me locally (change the tests index.php to use the dev version)

exussum12 avatar Jan 17 '16 15:01 exussum12

yes, it work now https://jsfiddle.net/bohdansemenets/j4frtfw9/ but if i have list for 3 elements and validateion was failed only for 2 item, can i add error message only to this field, same as main model? all field should have different id

MeterSoft avatar Jan 18 '16 08:01 MeterSoft

The fix for that is in src/field.js

The fiddle doesnt include that in. It was ok when i was testing

exussum12 avatar Jan 18 '16 13:01 exussum12

I'm very confused as to what files I have to take and how to make it work?

MeterSoft avatar Jan 18 '16 13:01 MeterSoft

Yeah sorry about that. I can't compile the main file for the pull because it will create conflicts when merging. You may be able to include the SRC/field.js in with your fiddle. Not 100% sure

I'll upload how I was testing later today

exussum12 avatar Jan 18 '16 13:01 exussum12

clone the codebase, and put this in the tests folder

http://pastebin.com/wDjVgXfv

Its your jsfiddle with the code change here

I cant add to the fiddle for some reason.

exussum12 avatar Jan 18 '16 21:01 exussum12

http://pastebin.com/24L8CZsy backbone forms min

http://pastebin.com/uUvniwAC list min

Hope that helps

exussum12 avatar Jan 18 '16 21:01 exussum12

i put your code to test folder and it not working

http://i.imgur.com/30fCPn5.png

then i replaced /extra/list on https://github.com/exussum12/backbone-forms/blob/6e48b0bb36761886bee7e990fec7b137f8e5f6f4/src/editors/extra/list.js This fix is not located in master?

and now it began to work, but not quite right, instead of the actual error message We can see the same messages

http://i.imgur.com/NDP1zva.png

MeterSoft avatar Jan 19 '16 09:01 MeterSoft

@exussum12 Hi, I can't find a contact email for you, wanted to ask if you were interested in becoming a project admin as I don't have time to maintain this project any more.

powmedia avatar Jan 20 '16 15:01 powmedia

screenshot_2016-01-20_19-18-13

Thats how I see it. @powmedia possibly, Ill email you - are you still using the email from your commits ?

exussum12 avatar Jan 20 '16 19:01 exussum12

@exussum12 yep On 20 Jan 2016 19:19, "Scott Dutton" [email protected] wrote:

[image: screenshot_2016-01-20_19-18-13] https://cloud.githubusercontent.com/assets/1102850/12460214/9bf664a8-bfaa-11e5-87f8-6aa63c55805e.png

Thats how I see it. @powmedia https://github.com/powmedia possibly, Ill email you - are you still using the email from your commits ?

— Reply to this email directly or view it on GitHub https://github.com/powmedia/backbone-forms/issues/483#issuecomment-173330303 .

powmedia avatar Jan 20 '16 21:01 powmedia

Replied to your email. Let me know if you received it

exussum12 avatar Jan 21 '16 20:01 exussum12

On yours screenshot you use ?

http://pastebin.com/24L8CZsy backbone forms min

http://pastebin.com/uUvniwAC list min

MeterSoft avatar Jan 22 '16 14:01 MeterSoft

I'll post the code I was using. What browser and is are you using ?

exussum12 avatar Jan 22 '16 19:01 exussum12

Firefox 43.0 I would like to receive a code that you use, because not quite clear what the code is actual Also, whether the use of plug-in hidden fields such as id because when editing there is a need to send id neted models to server?

MeterSoft avatar Jan 22 '16 20:01 MeterSoft

jsfiddle seemed to work today, Added an example there

https://jsfiddle.net/zogkbnwe/2/

Can you confirm that works and then Ill work on the tests

exussum12 avatar Jan 22 '16 22:01 exussum12

yes, that works

MeterSoft avatar Jan 24 '16 11:01 MeterSoft

what about support hidden id field, after submit form, it should ignore blank id fields, is it possible?

MeterSoft avatar Jan 24 '16 11:01 MeterSoft

This doesnt change the current behaviour for hidden forms ?

exussum12 avatar Jan 24 '16 15:01 exussum12

In documentation not have information about this. i try added id field to schema and add hidden class to them, but when it is new form after commit it return empty id ("") so we should remove it from hash before send to server

it is very inconvenient, I think the form must take id and transmit the it if it is present

MeterSoft avatar Jan 25 '16 07:01 MeterSoft