Solved

Add pre value to jquery easy ui add record text box

Posted on 2014-12-21
27
1,351 Views
Last Modified: 2014-12-21
i have been working with the crud interface form
http://www.jeasyui.com/demo/main/

i have searched the forums and i have tried varous ways with jquery and html textboxes to add a preloaded value to the textbox

i got it to do icons and placeholders just fine from this page
http://www.jeasyui.com/documentation/index.php click on textbox under form section on left hand menu

i cant get it to pre-populate a value in the box, any ideas?

thank you for any code or help you may provide
0
Comment
Question by:Johnny
  • 17
  • 10
27 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40511642
Not sure I'm following you.
If you want an input to have a default value why not just set it in the value attribute
0
 

Author Comment

by:Johnny
ID: 40511663
@Gary
because the way this js works it takes it over..and he has a way to do it but i cant get it to work at all

ive tried a few things
 //$("#Court_Case_Number").val("<?=$Court_Case_Number;?>");
//$('#Court_Case_Number').textbox({prompt:'<?=$Court_Case_Number;?>',readonly:'true'})

    				<label>Case #:</label>
    				<input name="Court_Case_Number" id="Court_Case_Number"  Title="" placeholder="Please enter Case #" value="<?=$Court_Case_Number;?>" class="easyui-textbox"  required="true">
    				<!--
    				<input name="Court_Case_Number" id="Court_Case_Number"  Title="Read ONLY" READONLY value="<?=$Court_Case_Number;?>" type="text" class="">
    				
    				<input class="easyui-textbox" name="Court_Case_Number"
				        data-options="
				            value:'<?=$Court_Case_Number;?>',
				            valueField:'id',
				            textField:'text'
				            ">
				-->
    			</div>

Open in new window


as i said i can only get icons and prompt to work...to set a value does not work, i haven't found it.

try downloading it and try it you will see what i mean im trying to populate the EDIT (form) popup like the first name field
0
 

Author Comment

by:Johnny
ID: 40511667
how it renders
<div class="fitem">
    				<label>Case #:</label>
    				<input id="Court_Case_Number" title="" placeholder="Please enter Case #" value="test-1234" class="easyui-textbox textbox-f" required="true" textboxname="Court_Case_Number" style="display: none;"><span class="textbox textbox-invalid" style="width: 160px; height: 22px;"><input type="text" class="textbox-text validatebox-text textbox-prompt validatebox-invalid" autocomplete="on" placeholder="" style="margin-left: 0px; margin-right: 0px; padding-top: 1px; padding-bottom: 1px; width: 157.777777671814px;" title=""><input type="hidden" class="textbox-value" name="Court_Case_Number" value=""></span>
    				<!--
    				<input name="Court_Case_Number" id="Court_Case_Number"  Title="Read ONLY" READONLY value="test-1234" type="text" class="">
    				
    				<input class="easyui-textbox" name="Court_Case_Number"
				        data-options="
				            value:'test-1234',
				            valueField:'id',
				            textField:'text'
				            ">
				-->
    			</div>

Open in new window

0
 

Author Comment

by:Johnny
ID: 40511672
sorry thats the html heres the dom render
http://prntscr.com/5jcq28
0
 
LVL 58

Expert Comment

by:Gary
ID: 40511684
It's working fine for me even using your code.
0
 

Author Comment

by:Johnny
ID: 40511694
can you please show me an example of if as an image im talking about the edit popup here
like this
http://prntscr.com/5jcxrf
0
 

Author Comment

by:Johnny
ID: 40511698
even adding value="test" to the dom does now work
http://prntscr.com/5jcyr5
0
 
LVL 58

Expert Comment

by:Gary
ID: 40511701
Which one are you using, tried a few of the modal windows and they all work.
0
 

Author Comment

by:Johnny
ID: 40511711
@Gary
datagrid
		$(function(){
			$('#dg').edatagrid({
				url: 'get_counsel.php',
				queryParams: {Court_Case_Number: '<?=$Court_Case_Number;?>'},
				saveUrl: 'save_counsel.php',
				updateUrl: 'update_counsel.php',
				destroyUrl: 'destroy_counsel.php',
			});
		});

Open in new window

0
 

Author Comment

by:Johnny
ID: 40511712
@Gary

so how are you making this work then - please explain and show an example
 thank you
0
 
LVL 58

Expert Comment

by:Gary
ID: 40511717
I'm confused, you started talking about a textbox, then a popup and now a datagrid

Which sample are you using to get the popup?
0
 

Author Comment

by:Johnny
ID: 40511722
@Gary

if i change the line to
<input name="Court_Case_Number" id="Court_Case_Number"  value="<?=$Court_Case_Number;?>" Title="" placeholder="Please enter Case #" value="<?=$Court_Case_Number;?>" class="easyui-textbox"  >

Open in new window


it makes it
<input id="Court_Case_Number" value="test-1234" title="" placeholder="Please enter Case #" class="easyui-textbox textbox-f" textboxname="Court_Case_Number" style="display: none;">

Open in new window


http://prntscr.com/5jd7v1

if i take out class
class="easyui-textbox" and make it class=""

Open in new window

it then shows the placeholder and the title but nothing else

http://prntscr.com/5jd8h2
0
 

Author Comment

by:Johnny
ID: 40511729
@gary i said it correctly from the beginning

i used the datagrid form this page (first name example for users) Basic crud example http://www.jeasyui.com/demo/main/

i am using the edit user (plus sign) to have the popup (as in the basic crud example)

i looked over the documentation and it has a textbox routine i used those examples to get the placeholder and the icons examples to change (see commented out code in my above paste of the block of code im talking about)

i have not been able ot at all get it to show the vlaue as a pre-populated value at all even with changing the several inputs it makes to mod this via js..non of them work adding value="test" to the dom at all

so ive tried
1: adding directly to dom
2: adding to code via normal vlaue= input html code
3: using textbox examples from the documentation on the site for all of the fields
4: jquery to force the val
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 58

Expert Comment

by:Gary
ID: 40511730
The value is got from the datagrid, why would you be setting it in the input?

Sounds more like you want placeholder text.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40511755
Placeholder text is not a value attribute - it's a completely seperate attribute you set in the input.
0
 

Author Comment

by:Johnny
ID: 40511794
@gary

Please understand i can ONLY get placeholder to work and not VALUE - VALUE is what im trying to pre-populate into the edit form field for lets say simply the first name in the demo..reason is im reading info from mysql database and its for the information im editing in the table

you know what i originally tried to pass a hidden input and it does not recognize it when its passed to a  php file via the save routine ajax call. that would work too..

i am good if i can add that to this block too but i could not figure that out either
        function saveUser(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.errorMsg){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }

Open in new window


i really just need to see the vlaue of the casenumber in my project,,or pre-populate a read only field or a hidden field..anything nothing works with this js routine im using, as i said i been trying to figure this out for awhile now trying different things
0
 

Author Comment

by:Johnny
ID: 40511800
let me recap a bit as this seams to be getting out of hand.

i have a value of case_number in this case "test1234" i need it to be passed when a user fills out the popup edit form and hits save

i tried and forgot i tried input hidden, i tried all the stuff we have been saying in varous ways for even pre-populating a input textbox, and all i got to work was the ability to add icons and placeholder text to the popup field lets say first-name here as thats in the basic crud example. i forgot all about it..as i said i been working on this for awhile now.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40511834
All I can suggest is in the save function:

$("#fm > .fitem:nth-child(1) > input").attr("value","test") // first name is the first child

Any value you set on the input is not passed and is cleared if you click into it.
0
 

Author Comment

by:Johnny
ID: 40511835
this does not work either
    			<div class="fitem">
    				<label>Case #:</label>
    				<?=$Court_Case_Number;?>
    				<input name="Court_Case_Number" id="Court_Case_Number"  HIDDEN value="<?=$Court_Case_Number;?>" class="">

Open in new window

shows fine in render
but does not pass to the ajax call in my php

http://prntscr.com/5jdwdu
as you can clearly see in this image the hidden input has the vlaue of test-1234 the popup has the value of test-1234 but the returned json vlaue is blank and is not processed in the php file to save to the database it gets lost someplace
0
 

Author Comment

by:Johnny
ID: 40511838
@Gary

*thanks for the help too i truly am grateful*
how would i get this to pass as i need the field to be "case_number"

$("#fm > .fitem:nth-child(1) > input").attr("value","test") // first name is the first input
0
 

Author Comment

by:Johnny
ID: 40511845
@Gary

did i place this in the wrong spot it didnt do a  thing

		function saveCounsel(){
			//alert('url '+url);
			// gets here
			$("#fm > .fitem:nth-child(1) > input").attr("value","test"); // first name is the first input
			$('#fm').form('submit',{
				url: url,
				onSubmit: function(){
					//alert('submit');
					return $(this).form('validate');
				},
				success: function(result){
					alert('result '+result);
					var result = eval('('+result+')');
					if (result.errorMsg){
						$.messager.show({
							title: 'Error',
							msg: result.errorMsg
						});
					} else {
						$('#dlg').dialog('close');	// close the dialog
						$('#dg').datagrid('reload');	// reload the user data
					}
				}
			});
		}

Open in new window

0
 

Author Comment

by:Johnny
ID: 40511846
@Gary
fyi this is my save php file
<?php
session_start();  // needed for sessions.

$Counsel_Name = $_REQUEST['Counsel_Name'];
$Location = $_REQUEST['Location'];
$Counsel_Phone = $_REQUEST['Counsel_Phone'];
$Counsel_Fax = $_REQUEST['Counsel_Fax'];
$Counsel_Email = $_REQUEST['Counsel_Email'];
$Court_Case_Number = $_REQUEST['Court_Case_Number'];

include_once ("../mysqli_ctx.php");

$sql = "insert into Opposing_Counsel(Counsel_Name,Location,Counsel_Phone,Counsel_Fax,Counsel_Email,UserID,Court_Case_Number) values('$Counsel_Name','$Location','$Counsel_Phone','$Counsel_Fax','$Counsel_Email','".$_SESSION['USER_ID']."','$Court_Case_Number')";
@mysqli_query($mysqli,$sql);
echo json_encode(array(
	'id' => mysqli_insert_id($mysqli),
	'Counsel_Name' => $Counsel_Name,
	'Location' => $Location,
	'Counsel_Phone' => $Counsel_Phone,
	'Counsel_Fax' => $Counsel_Fax,
	'Counsel_Email' => $Counsel_Email,
	'Court_Case_Number' => $Court_Case_Number
));
mysqli_close($mysqli);
?>

Open in new window


all but Court_Case_Number saves fine in the database
0
 
LVL 58

Expert Comment

by:Gary
ID: 40511847
I would set the placeholder text and disable the input.

Then in the saveUser function set the real input value (you could do it in newUser() as well)

        function saveUser(){
            $("[textboxname=case_number]").attr("value","test") // pass the case number in here

            $('#fm').form('submit',{
                url: url,

Open in new window


Change this to the real name
textboxname=case_number
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40511857
If it is just the one param why not append it the save url

url: url + "?case_number=" + $("some_hidden_input").val(),
0
 

Author Closing Comment

by:Johnny
ID: 40511881
DING DING DING we have a winner


thank you so much... that worked out great after all that something simple...

*smile* Have a Happy Holidays
0
 

Author Comment

by:Johnny
ID: 40511883
still curious if its possible to add info to the text box too..i case anyone wants to try!
0
 
LVL 58

Expert Comment

by:Gary
ID: 40511884
You too
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now