Formio:- Custom Error Message when the submit button is pressed without filling the required fields - formio

I would like to change the error message that is displayed in situations where we click the submit button, but some compulsory fields are empty. The message that I receive by default is "Please check the form and correct all errors before submitting the form". I want to use instead a custom message. Is there a way to achieve this ?

You can override the error message by adding to the options when creating a form:
var options = {
i18n: {
en: {
submitError: 'My custom submission error',
}
}
}
And then later you're probably doing a call to
Formio.createForm(Formio.createForm(document.getElementById(settings.id), formDefinitionUrl, options)
which is where the options object you need is found.
Here's a list of the strings you can override this way: https://github.com/formio/formio.js/blob/master/src/translations/en.js

Related

GLib.Notification fails to activate action with a non-null VariantType

I'm trying to send a GLib.Notification from my application and pass a string parameter.
The name of the action is action-show-chat-view, and it is registered in the activate () method of my main application class:
public class MyApplication : Gtk.Application {
protected override void activate () {
// ...
var show_chat_view_action = new GLib.SimpleAction ("action-show-chat-view", GLib.VariantType.STRING);
show_chat_view_action.activate.connect ((parameter) => {
debug ("beep boop");
debug (parameter.get_string ());
});
add_action (show_chat_view_action);
// ...
}
}
To send the notification, I do the following:
var notification = new GLib.Notification ("Hello, world");
var target = new GLib.Variant.string ("foobar");
notification.set_default_action_and_target_value ("app.action-show-chat-view", target);
app.send_notification (null, notification); // app is the instance of the MyApplication class above
The notification is sent correctly and appears as expected, however when the notification is clicked to activate the action, I receive the following error:
GLib-GIO-CRITICAL **: 13:04:37.169: g_simple_action_activate: assertion 'simple->parameter_type == NULL ? parameter == NULL : (parameter != NULL && g_variant_is_of_type (parameter, simple->parameter_type))' failed
Other things that I've tried:
If I replace GLib.VariantType.STRING with null, and pass null as the target value on the notification (and removing parameter.get_string ()), I see the "beep boop" console output so I know that everything is at least wired up correctly and calling the right methods.
I have also tried registering the action with the app. prefix as well, however I read somewhere in documentation that when added via the Application.add_action () this is implicit.
I tried creating an action group with the type string s but got the same error.
I've tried using other Variant types besides STRING
I tried adding the following check before sending the notification to see if the types align, and they did: app.get_action_parameter_type ("action-show-chat-view").equal (target.get_type ()). This failed if I used the app. prefix, however I think that's expected behavior since it's registered without the prefix?
I looked into Flatpak sandbox permissions (this part is all new to me), but since the notification is sent successfully, I don't think that's the problem.
This appears to have been a bug with xdg-desktop-portal-gtk: https://github.com/flatpak/xdg-desktop-portal-gtk/pull/359. Despite being fixed, it has not yet been included in a release.
Some related discussion on an issue logged with elementary/notifications: https://github.com/elementary/notifications/issues/153

Get newly created id of a record before redirecting page

I would like to retrieve the id of a newly created record using javascript when I click on save button and just before redirecting page.
Do you have any idea please ?
Thank you !
One way to do this in Sugar 7 would be by overriding the CreateView.
Here an example of a CustomCreateView that outputs the new id in an alert-message after a new Account was successfully created, but before Sugar gets to react to the created record.
custom/modules/Accounts/clients/base/views/create/create.js:
({
extendsFrom: 'CreateView',
// This initialize function override does nothing except log to console,
// so that you can see that your custom view has been loaded.
// You can remove this function entirely. Sugar will default to CreateView's initialize then.
initialize: function(options) {
this._super('initialize', [options]);
console.log('Custom create view initialized.');
},
// saveModel is the function used to save the new record, let's override it.
// Parameters 'success' and 'error' are functions/callbacks.
// (based on clients/base/views/create/create.js)
saveModel: function(success, error) {
// Let's inject our own code into the success callback.
var custom_success = function() {
// Execute our custom code and forward all callback arguments, in case you want to use them.
this.customCodeOnCreate(arguments)
// Execute the original callback (which will show the message and redirect etc.)
success(arguments);
};
// Make sure that the "this" variable will be set to _this_ view when our custom function is called via callback.
custom_success = _.bind(custom_success , this);
// Let's call the original saveModel with our custom callback.
this._super('saveModel', [custom_success, error]);
},
// our custom code
customCodeOnCreate: function() {
console.log('customCodeOnCreate() called with these arguments:', arguments);
// Retrieve the id of the model.
var new_id = this.model.get('id');
// do something with id
if (!_.isEmpty(new_id)) {
alert('new id: ' + new_id);
}
}
})
I tested this with the Accounts module of Sugar 7.7.2.1, but it should be possible to implement this for all other sidecar modules within Sugar.
However, this will not work for modules in backward-compatibility mode (those with #bwc in their URL).
Note: If the module in question already has its own Base<ModuleName>CreateView, you probably should extend from <ModuleName>CreateView (no Base) instead of from the default CreateView.
Be aware that this code has a small chance of breaking during Sugar upgrades, e.g. if the default CreateView code receives changes in the saveModel function definition.
Also, if you want to do some further reading on extending views, there is an SugarCRM dev blog post about this topic: https://developer.sugarcrm.com/2014/05/28/extending-view-javascript-in-sugarcrm-7/
I resolved this by using logic hook (after save), for your information, I am using Sugar 6.5 no matter the version of suitecrm.
Thank you !

How do I validate a single form field in CodeIgniter?

I have a form that has validation rules that are set in a config file. I want to validate this form field using AJAX so that when focus leaves a certain form field, that field is checked by CI's form validation class. I have a jQuery AJAX script that calls one of my controllers which I would like to have validate the form field. using the form_validation->run('group') method won't work for this because it checks everything in the form and will always return false. How can I validate a single form field in CodeIgniter?
For this you could use a custom jquery function like:
//When the focus leaves the desired input, do the check with JS or with CI
$('#the_input').focusout(function() {
//check values here or send to php with ajax
if($(this).val == ''){ //I.E check if is blank
alert("Blank!");
return false;
}
//Or 'asking' to CI
var url = "/path/to/codeigniter/function";
$.get(url,function(data){
if(data == true){
alert("OK!");
}
});
});
If you wish, you could do this as a function returning true or false (instead of onMouseFocus), and call from your proper CI validation flow, like:
isInputXvalid(input){ //... return isValid; }
Hope it helps!

grails: custom validation of just one field/property

I have a "Thing" domain class, where each Thing has an record number (which is not the automatically generated id), that the user will use to access a Thing:
class Thing {
...
String recordNumber
...
}
There is a form to look for a Thing, knowing its recordNumber:
<g:form action="search">
<input name="recordNumber">
<g:submitButton name="btn" value="go to this Thing"/>
</g:form>
I would like to use a validation process in this form: if the recordNumber is not found (Thing.findByRecordNumber(recordNumber) == null), then the input field must turn in red, and a tooltip must show the error message "record number not found".
As far as I know/read (I'm a grails rookie), this has to be written as a constraint in the Thing class:
static constraints = {
recordNumber validator: { n -> Thing.findByRecordNumber(recordNumber) }
}
The problem is: I do not have in this form all the "Thing" properties to populate, just the recordNumber one, so I just can't call
new Thing(params).validate()
How to call validation on just one field, not on the whole object ?
If this is your main question, although I see others there:
"How to call validation on just one field, not on the whole object ?"
You can pass a list of values to validate and it will only validate those properties
new Thing(params).validate(["recordNumber"])
http://grails.org/doc/latest/ref/Domain%20Classes/validate.html
Validation is for constraints for domain class properties. You need an action in your controller:
def search = {
if(params.recordNumber && Thing.findByRecordNumber(params.recordNumber)){
redirect(action: "show", params:[id:Thing.findByRecordNumber(params.recordNumber).id])
}else{
flush.message = "No record found"
render(view:'VIEW_WITH_SEARCH_FORM')
}
}
If you want to validate without refreshing page, write a javascript code.

Zend_Form - How to addValidator after the form has been submitted

I have 2 text fields in my form.
TextFieldA - not required
TextFieldB - not required
After user submitted the form,
How to add validator / setRequired(true) to TextFieldB if the value of TextFielA is not empty?
I see two approaches in addition to #Marcin's idea.
Conditionally call setRequired() on the relevant elements by creating a preValidate() method on the form and calling it in your controller. [Really the same idea as #Marcin, but pushed down into the form itself, keeping the controller a bit leaner.]
Create a custom validator called something like ConditionallyRequired that accepts as an option the fieldname of the "other field". Then attach this validator to each element, configuring it with the name of the "other" element. Then in the validator's isValid($value, $context) method, conditionally test $value if $context['otherfield'] is non-empty.
You could do as follows:
if ($this->getRequest()->isPost()) {
$textFieldA = $yourForm->getElement('TextFieldA');
$textFieldB = $yourForm->getElement('TextFieldB');
if (!empty($_POST['TextFieldA'])) {
$textFieldB->setRequired(true);
}
if (!empty($_POST['TextFieldB'])) {
$textFieldA->setRequired(true);
}
if ($mainForm->isValid($_POST)) {
// process the form
}
}
Basically, you add the validators after the post, but before the form is validated.
Hope this helps.