Prevent form submit via javascript

I have a two fields where the user is required to fill only one of them, while the other can be blank. He can also fill both, doesn't matter.

This can not be done with Knack itself (or I don't know how) so I have to resort to a simple custom javascript validation. If both fields are empty, I show an error message and stop the form submitting. And here is my problem. How can I prevent Knack from submitting the form manually? If I listen to the submit event and do a 'return false', it doesn't work. Since I can not see an action url in the form element, I am thinking Knack has it's own form submit logic. How can I capture that and stop it from submitting the form?

Thank you!

Hola, estoy interesado en ingresar la documentación pero no puedo iniciar sesión para ver, habrá una forma de obtener la documentación desde otro lado o por favor díganme cuál fue la solución que encontró
---------------Detectar idiomaAfricaansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEnglishesperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreohindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínDejar enLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratímongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioSesotho meridionalShonaSindhiSomalíSuajiliSuecoSundanésTagaloTailandesaTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEnglish
 
 
Hello, I am interested in entering the documentation but I can not log in to see, there will be a way to get the documentation from another side or please tell me what was the solution you found

Detectar idioma
Afrikáans
Albanés
Alemán
Amárico
Árabe
Armenio
Azerbaiyano
Bengalí
Bielorruso
Birmano
Bosnio
Búlgaro
Canarés
Catalán
Cebuano
Checo
Chino (Simplificado)
Chino (Tradicional)
Cingalés
Coreano
Corso
Criollo haitiano
Croata
Danés
Eslovaco
Esloveno
Español
Esperanto
Estonio
Euskera
Finés
Francés
Frisón occidental
Gaélico escocés
Galés
Gallego
Georgiano
Griego
Guyaratí
Hausa
Hawaiano
Hebreo
Hindi
Hmong
Húngaro
Igbo
Indonesio
Inglés
Irlandés
Islandés
Italiano
Japonés
Javanés
Jemer
Kazajo
Kirguís
Kurdo
Lao
Latín
Letón
Lituano
Luxemburgués
Macedonio
Malayalam
Malayo
Malgache
Maltés
Maorí
Maratí
Mongol
Neerlandés
Nepalí
Noruego
Nyanja
Panyabí
Pastún
Persa
Polaco
Portugués
Rumano
Ruso
Samoano
Serbio
Sesotho meridional
Shona
Sindhi
Somalí
Suajili
Sueco
Sundanés
Tagalo
Tailandés
Tamil
Tayiko
Telugu
Turco
Ucraniano
Urdu
Uzbeko
Vietnamita
Xhosa
Yidis
Yoruba
Zulú

Español

 
 
Hola, estoy interesado en ingresar la documentación pero no puedo iniciar sesión para ver, habrá una forma de obtener la documentación desde otro lado o por favor díganme cuál fue la solución que encontró

Thank you Brad, I don't know how I missed that, I was searching around a lot for custom validation, since I thought this isn't a too exotic request. Still didn't find that :/

In my tries I was listening to the form submit event. Apparently Knack is listening on the click event for the submit button. That's probably why my 'return false' didn't do anything, since it had no effect on the click event.

It is working now with the code provided in the example. I am very happy, thank you very much!!

Markus - check out the documentation for javascript code examples and this custom validation snippet: http://helpdesk.knackhq.com/support/solutions/articles/5000447560-javascript-code-examples#jqcustomvalidate

Thank you very much, this is close enough and should work just fine, thanks!

Coming back to the original question though, is it possible to intercept the knack form submission? For example validating a name field does not work this way, because inside knack, the name is one field and I can not select first and last name separately. We want to send the data to zapier and to another app which chokes on missing first or last names since they are required there. Knack however does accept only first name or only last name. Do you have any idea about that?

Then you can set validation rule in your DB object

Just select either one of the 2 fields and set validation rule : 

When "field 1" "is blank"

When "field 2" "is blank"

Show message : "please fill at least 1 field"

Thank you for your reply, my scenario is, that ONE of both are required, not both. In Data I can either set both to required or none or just one but that doesn't solve the problem.
I need to do custom validation (another thing is that the name field gets validated by knack if only first or last name is filled, so there it is the exact opposite) in order to accept the form if only one of the two fields are filled, but reject it, if none of them are filled.

Hi.

In data > object, you can set the required field option > settings as "required".

I think it will solve your pb