Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

Add pre value to jquery easy ui add record text box

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
Avatar of Gary
Gary
Flag of Ireland image

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
Avatar of Johnny

ASKER

@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
Avatar of Johnny

ASKER

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

Avatar of Johnny

ASKER

sorry thats the html heres the dom render
http://prntscr.com/5jcq28
It's working fine for me even using your code.
Avatar of Johnny

ASKER

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
Avatar of Johnny

ASKER

even adding value="test" to the dom does now work
http://prntscr.com/5jcyr5
Which one are you using, tried a few of the modal windows and they all work.
Avatar of Johnny

ASKER

@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

Avatar of Johnny

ASKER

@Gary

so how are you making this work then - please explain and show an example
 thank you
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?
Avatar of Johnny

ASKER

@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
Avatar of Johnny

ASKER

@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
The value is got from the datagrid, why would you be setting it in the input?

Sounds more like you want placeholder text.
Placeholder text is not a value attribute - it's a completely seperate attribute you set in the input.
Avatar of Johnny

ASKER

@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
Avatar of Johnny

ASKER

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.
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.
Avatar of Johnny

ASKER

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
Avatar of Johnny

ASKER

@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
Avatar of Johnny

ASKER

@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

Avatar of Johnny

ASKER

@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
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
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johnny

ASKER

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
Avatar of Johnny

ASKER

still curious if its possible to add info to the text box too..i case anyone wants to try!
You too