How to make required fields using JS - sharepoint-2010

I have a SharePoint Form. How can I make a required field( people picker and date) using Java Scripts ? Thanks in advance

Check the OOTB options first. Obviously a list field marked required will not submit until it's filled in.
You can also setup validation in list setting under validation settings. Enter a formula that can evaluate to TRUE to pass validation (Title = "TitleXYZ"). Custom error text can also be added.
There are endless options using JavaScript. The basic SharePoint forms model (assuming your validating on the submit event) uses the PreSaveItem function:
function PreSaveItem()
{
if ("function"==typeof(PreSaveAction))
{
return PreSaveAction();
}
return true;
}
PreSaveAction function also allows override behavior for the Save button. For example:
function PreSaveAction() {
return ifValidSSN();
}
You can find a good example of using this function
here
If you want more of a framework there are multiple jQuery validation plugins you can try. I recommend the jquery Validation plugin
If you want some examples of using this plugin let me know

Related

formvalidation.io disable validation for entire form

I am using formvalidation.io for our form validation.
Works great if we want to validate the form but we have functionality where we want to allow a user to save a draft of the form. In this scenario we don't want to do validate any part of the form. We don't want to disable each validator we want to disable the entire validation process. I tried using formnovalidate and it worked in Chrome but would not work in IE. What is the best method to do this for all browsers? Any suggestions?
I'm not sure if it's still relevant to you, but in case someone else stumbles across it (like I did with a slightly different problem);
We have included the 'novalidate' attribute in the formvalidation initial setup, eg:
$('form').each(function() {
if (!$(this).is('[novalidate]')) {
$(this).formValidation({
//form validation config
});
}
});

Prestashop 1.6: how to load a different template after an admin form submission?

I'm new to Prestashop and currently working on a custom admin module in 1.6.
My scenario is, users can load orders to this module/admin controller and from the list they can select which ever order they like using 'Select All' checkbox selector.
And then these selected order ids are submitted back to admin controller to be displayed on a different template with full information in a form.
And then again this form will be submitted to a third party API for further processing.
Now my problem is I can get the order listing to my admin controller and get them submitted back to the same controller. But I do not know how to switch to a different template to display in a form.
And also how to call a different method to process and export once second form substitution is done.
Any advice would be greatly appreciated.
Thanks in advance
Roshan
In your AdminController extend the method initContent with a condition that is you need to check if a certain button was pressed. Something like
public function initContent()
{
if (Tools::isSubmit('the_button')) {
'do what you want to do'
}
parent::initContent();
}
if you want to redirect to a different controller use Tools::redirectAdmin() and set the path of redirection like Context::getContext()->link->getAdminLink('your_another_controller', true), also you can send all necessary data with the third parameter of the method(array)
public function initContent()
{
if (Tools::isSubmit('the_button')) {
Tools::redirectAdmin(
Context::getContext()->link->getAdminLink('your_another_controller', true, $orders)
);
}
parent::initContent();
}
You can use as many conditions, inside the method, as you need so I hope it will help you in all your cases.

TYPO3 Plugin - One action public access and one private

I'm developing an extension that have both, a list of records (action show) and a form to send a new record (action new).
The list must be for public access, but the form must require a login form (I'm using the login form content type that comes with TYPO3).
I have tried using the Access Tab for the plugin selecting Show at any Login but it applies to the entire plugin not for each action.
Currently, this is how the page looks like:
How could I get to display the login form only when someone tries to create a new record?
Note: The extension is based on Extbase and Fluid. The target version is TYPO3 6.2.
The easiest would be to split the actions in different "views" with switchableControllerActions in your flexform. Then you would need to place separate plugins on two different pages, that way you can have different access configuration for the plugins. If you don't know how to adjust the flexform, you can post the content of it here.
The other way would be to make a check inside the controller, but i would only use it if you have a lot of different roles you need to check.
if ($this->loginUser === null && $GLOBALS['TSFE']->loginUser && !empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
// the user is logged in
} else {
// return '' as action content
return '';
}

Yii: ClientSide Validation on FileField and TextField

I have a yii form with a file field and a normal text field for supplying an external image url. I managed to get a normal server validation working which checks that only one of the two form fields is filled out (because you can either provide a local file for uploading OR an external picture URL). Important to notice is, that the attribute value of the "file field" seems only to be available after the $_POST var is set, meaning that a normal custom validation rule in the Model Class won't work since the $_POST value of the file field is only available after submission (in the $_FILES var).
But if you look at my provided picture below, I want also a ClientSide Validaton, so that the user gets immediate feedback that it's not allowed to fill out both fields. But how do I accomplish that? I'm sitting on this problem for about 2 days, half of the time on searching for solutions...I am new to Yii.
http://www.prism-informatics.com/images/demo.png
Best wishes,
S
I am not completely sure what your problems is as you didnt provide any code but i assume you forgot :
public function rules()
{
return array(
array('image', 'file', 'types'=>'jpg, gif, png'),
);
}

Using google places api with jQuery autocomplete

I'm using google places and jquery to achieve the goal of once the user starts typing in an input field, it does a call to google places and feeds the results in a dropdown (via jquery ui autocomplete)
My problem is, in my autocomplete function I have
source: function( request, response ) {
initialize()
}
In there, I'm trying to call this function
function initialize() {
service.search(request, callback);
}
Which works fine... but the problem is... initialize does a call out to the function callback()... so I'm not sure how to listen to see when the callback is done.
So for example, what would I do here:
source: function( request, response ) {
// need code here to know when initialize and callback are done and are sending me the list of results from google ?
}
I'm just not sure how to wait for google places to get done, before I use $.map from the results to produce the dropdown.
Timing issues with google apis? I feel your pain. But to sidestep your issue and maybe save you some pain, you could use Google's prebuilt solution:
http://code.google.com/apis/maps/documentation/javascript/places.html#places_autocomplete
Apologies if you have some reason to not use their API.