Adding javascript function to a grocerycrud add or edit form - codeigniter

Is it possible to add a javascript function to the add/edit forms of grocery_CRUD?
E.g. As a user is typing in a particular field when adding or editing a record I want to execute a javascript on the keydown event.
If so, how?

It is possible.
For example, you call the view like this:
$this->load->view('grocery_crud_view', $output);
In the beginning of the view (grocery_crud_view.php), you can add any javascript
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascrpt">
$("#field-code").keyup(function(){
alert("there is a keyup");
});
</script>
<?php
// The rest of default php code
?>
Most of the id of the grocery-CRUD view (if you use flexigrid theme) would be something like this : "field-your_field_name"
You can inspect with firebug or google-chrome developer tools to ensure it.

Related

Edit hyperlink validation

Is there any possibility to add another protocol to the hyperlink-type in sharepoint?
I want to add a notes (notes://***) to the top level navigation-bar.
Is there something I can extend or where I can edit the validation
By default, SharePoint navigation Hyperlinks must begin with http://,https://,mailto:,ftp://,file://,/,# or \.
If you want to use the "notes://***", as a workaround, you can add the link using jQuery code.
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$(".ms-core-listMenu-horizontalBox>ul>li>ul").append("<li class='static'><a href='notes://xxx'>MyNote</a></li>");
});
</script>
Probably it is not possible to turn off easily the OOB link validation without any customization. Depends on the output You need maybe You could use a note column and in edit HTML content of the filed just put the link tag manually like:
someLink
. After save SharePoint will render it as link on list webpart.

validation does not work in popup form values in magento

I am using Ajax for sending data on controller. Here I use TinyMCE editer in my popup form and I need to validate it. But here validation does not work properly in Magento.
Yes you should clarify more on this.
By the way wherever you have put your form in popup give it an ID like and in your form if you have text boxes then put class 'required-entry' in all required textboxes and you should have one submit button.
Then finally put this script after form :
<script type="text/javascript">
//<![CDATA[
var popupForm = new VarienForm('popupform', true);
//]]>
</script>
See how it goes.

TinyMCE not working on Ajax calls

I have a select.php page where the user selects a value from the dropdown. On selection the ajax code runs and information from ajax.php gets populated on the "display" div of the select.php page. Some of the information coming from ajax.php is in the form of textarea. But it gets displayed just as textarea, and not as tinymce editor. Even though I have called it in the head section of my page.
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
tinymce.init({
selector: 'textarea'
});
</script>
My problem is very similar to this: How do I initialize TinyMCE on a ajax loaded textarea in 4.x?
But I am not understanding the solution. Please help.
you can get data after that set data on tiny
success: function (data) {tinyMCE.get(data).getContent().replace('\'', "\’");},
Your call to tinymce.init() only acts on items in the DOM at the time the init() function is run. If you are adding additional <textarea> fields to the page later you need to run tinymce.init() after you add those elements to the DOM.
You can include a call to tinymce.init() in the same block of code that injects the <textarea> into the page directly after you inject the <textarea>.

How to call alert() javascript function in CodeIgniter

How could I display an alert from the controller class in CodeIgniter?
Typically you want to place any display content (such as HTML or Javascript) in a view, not in a controller. From the controller you load the view, and the view contains this code somewhere in it:
<script type="text/javascript">
alert('your alert');
</script>
See the CodeIgniter user_guide for more basics on how to structure your application:
http://www.codeigniter.com/user_guide
Anything you "print" using PHP's print, displays to the screen.
print "<script type=\"text/javascript\">alert('Some text');</script>";

Is there a way of making normal links automatically load through ajax, rather than normally?

I haven't explained this well.
But what i mean is, if I have an ajax script that loads the content of a page in a DIV element, through the function 'loadpage('whatever.php');, instead of going around manually doing this to all links, is there a way of having a script that automatically makes all regular links load through that ajax function?
Like on Facebook, your profile loads through ajax, yet if you look at their code, they just have a regular link to the profile.
Cheers!
Sure, you can do it with jQuery.
This script goes through the document, finds every anchor element and binds an event handler to the click event of each. When the anchor element is clicked, the event handler finds the href attribute and loads that page into #targetDiv (you can call this div whatever you want, of course).
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
$("#targetDiv").load(($(this).attr("href") + " body");
return false;
});
});
</script>
...
<!-- In your document body, this is the div you'd load the pages into. -->
<div id="targetDiv"></div>
You can use JQuery for this (if I understand your question right).
First you can make the function loadpage() as follows:
function loadpage(divId, url) {
$('#' + divId).load(url);
return false;
}
.load() isn't supported by all browsers though. If you want to do this without .load() then you can check out .get(). For more info on .load(), take a look at http://docs.jquery.com/Ajax/load
I'm assuming it would go something like this:
$(document).ready(function(){
$("a").click(function(){
$("body").load($(this).attr("href") + " body");
return false;
});
});
This would make all <a> tags on the page call a function that downloads a HTML document from the href attribute of the tag, strip out it's body tag, and replace the contents of the current page's body tag with the contents of the new body tag. This way, it's easier to work this with no JavaScript, as well as integrate it into an existing site.
To use it, you place this into a <script> tag in the head of your main page, or in an external JS file.
Please note, however, that this code only updates the contents of the <body> tag, the head (including the title tag) remains untouched. You may need to add extra code to update things like this.
Simple and Nice. Check this out:
Bjax
Usage:
<script src="bjax.min.js" type="text/javascript"></script>
<link href="bjax.min.css" rel="stylesheet" type="text/css" />
Finally, include this in the HEAD of your html:
$('a').bjax();
For more settings, checkout demo here:
Bjax Demo

Resources