Solved

Could you point how to manipulate a textbox value before it's presented?

Posted on 2016-10-14
12
65 Views
Last Modified: 2016-10-26
Hi Experts

Could you point how to manipulate a textbox value before it's presented?

Accordingly to:
img001
The value is presented with a file complete path, is it possible via jQuery to supress the path, maintaining only the file name, before it's presented ?
If so what is the event to be used?

Thanks in advance
0
Comment
Question by:Eduardo Fuerte
  • 6
  • 5
12 Comments
 

Author Comment

by:Eduardo Fuerte
ID: 41843657
After some researchs;

HTML (modal view)
<div class="col-xs-20 mb40 reembolso" style="display: none;">
		<label for="reembolso" class="field-label text-muted mb10">Anexo</label>
		<div class="input-group">
			<span class="input-group-addon">
				<i class="fa fa-money c-gray"></i>
			</span>
			<span class="validar">
				<input type="text" name="anexo" class="anexo form-control gui-input br-light light" placeholder="">
			</span>
		</div>
	</div>
</div>

Open in new window


jQuery : Since it's a modal view
$('#view').on('show.bs.modal', function () {

    var str = $('#view .anexo').val();
    alert(str);  // it produces an empty value

   // Manipulate here anexo value to get the relevant part:
   
    str = str.substrring(22);
   
//Make this value to be presented:
	$('#view .anexo').val(str);
});

Open in new window


When this event is called the anexo value is still filled ?
0
 
LVL 52

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41843659
Do you mean like this?
$(function() {
  var file = $('#textboxid').val();
  var parts = file.split('/');
  var file = parts[parts.length-1];
  $('#textboxid').val(file);
});

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41843670
You might also do this in the server-side script.  Have a look at the PHP basename() function and the predefined constant DIRECTORY_SEPARATOR..
0
 

Author Comment

by:Eduardo Fuerte
ID: 41843765
Since by now it's more a jQuery issue, I applied your code  on view  modal show event:

HTML in use now:
<input type="text" name="anexo" id="anexo" class="form-control gui-input br-light light" placeholder="">

Open in new window


$('#view').on('show.bs.modal', function () {
  
	var file = $("#view #anexo").val();
	var parts = file.split('/');
	var file = parts[parts.length-1];
	  
	alert(file);
	  
	$("#view #anexo").val(file);

});

Open in new window


Amazingly: The very first time the modal is called the value isn't filled:
img002

Then when it's called the next times, ok:
img003

And...the textbox doesn't assume the new value assigned:
img004
Could you give a suggestion?
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 41843786
Probably because the first time it runs the textbox has not been populated.

What is putting the value in the text box?
0
 

Author Comment

by:Eduardo Fuerte
ID: 41843822
The value is empty - accordingly the picture bellow.

It seens it has a "delay" - going the code above the logic goes right, even the first time the alert shows "0" it enables the "Download" button, if the alert shows "25" (f.e.) and the file lenght is zero it disables the "Download" button too.

$('#view').on('show.bs.modal', function () {
 
	var file = $("#view #anexo").val();
	var parts = file.split('/');
	var file = parts[parts.length-1];
	  
	alert(file.length);

	
	// Desabilita o botão de download
	 if(file.length != 0)
	 {
		$('#view #download').prop("disabled", true);     
	 }
	 else            
	 {
		$('#view #download').prop("disabled", false);
	 }
	 
// Not beeing done, yet
	$("#view #anexo").val(file);

});

Open in new window



Just the assignment is still not beeing done
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 52

Expert Comment

by:Julian Hansen
ID: 41843875
var file = $("#view #anexo").val();

Open in new window

Where is #anexo being set - the first line is retrieving the value of the control but something must be putting the filename in there?
0
 

Author Comment

by:Eduardo Fuerte
ID: 41843980
Wouldn't be it?   (line 21 above)

	$("#view #anexo").val(file);

Open in new window

0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 41844345
Yes but you are retrieving the value on line 3 - the value that you are retrieving - something is setting that - the full path?
0
 

Author Comment

by:Eduardo Fuerte
ID: 41849857
I'm just debbuging to better check and will return  here soon.
0
 

Author Closing Comment

by:Eduardo Fuerte
ID: 41860098
Thanks for help!
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 41860151
You are welcome.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

896 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

11 Experts available now in Live!

Get 1:1 Help Now