Just-validate icon indicating copy to clipboard operation
Just-validate copied to clipboard

Support for element along with String selectors in addField

Open shivam091 opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe. When I pass element in addField method, it throws error saying:

controller.ts:12 Error connecting controller

Error: Field selector is not valid. Please specify a string selector.
    at JustValidate.addField (just-validate.es.js? [sm]:732:13)
    at t.validateBlockedUserForm (blocked_users_controller-dbd7a6e1a7e0c96cfbb2407a377cda3204a890d09bcbca3bb0dbd8bd11a06fc3.js:34:25)
    at t.connect (blocked_users_controller-dbd7a6e1a7e0c96cfbb2407a377cda3204a890d09bcbca3bb0dbd8bd11a06fc3.js:13:10)
    at M.connect (controller.ts:12:39)
    at L.connectContextForScope (controller.ts:12:39)
    at controller.ts:12:39
    at Array.forEach (<anonymous>)
    at R.connectModule (controller.ts:12:39)
    at R.loadDefinition (controller.ts:12:39)
    at controller.ts:12:39

Describe the solution you'd like It would be better if selector ($(selector) / document.querySelector("selector")) is available along with string like


form.addField(document.querySelector("[name='field_name']"), [

])

Describe the solution you'd like It will be beneficial if I already have element specified somewhere inside my JS, I can pass that element directly here rather than setting string.

shivam091 avatar May 04 '22 07:05 shivam091

Hi! Thank you for the suggestion. For now a lot of internal implementations based on some uniq field id. Currently this is a selector, which could be any, like #id, .class, [data-attr="something"] but still these are uniq ids. In case of using a DOM element we don't have this uniq id, so this feature will require some extra work to have internal field ids based on DOM elements and I'm not sure I have time to implement it now unless we have many such suggestions and use-cases.

I will keep it opened, just in case in future it makes sense to do this :-)

horprogs avatar May 04 '22 10:05 horprogs

No worries.. You take your time..

Thank you

shivam091 avatar May 05 '22 14:05 shivam091

Hello thank you for this great and just works library. Adding this feature will be good for dynamically added form fields.

ecmel avatar Aug 22 '22 18:08 ecmel

Finally had some time to implement this. Now it should be possible to use a DOM element for addField, removeField, revalidateField methods

horprogs avatar Dec 10 '22 16:12 horprogs

Thanks @horprogs

shivam091 avatar Feb 04 '23 17:02 shivam091