Categories
Learning Tech

Placeholder input text color not changing HTML, browser chrome, how to fix?

Hello,

Welcome to the post, if you are facing similar issue on your webpage or simple app where you are trying to change the HTML input element placeholder text color according to your design or theme and changes are not applying you followed very basic documentation from MDW web docs placeholder

What is causing this issue is simple, I was facing similar issue with search field and I am using Chrome browser mainly as my default browser, so I haven’t check it was behaving right or not, so I was looking for the answers.

I have tried this solution from stakeoverflow added simple snippet from here but it still not showing reflection of change. so I though, I am writing my CSS code using SCSS, maybe I need to add in some other way or format syntax-ly, so stumbled upon on another stakeoverflow page, added the mixin in my scss code, hope to see the reflection of color change to placeholder text of input field, sorry this time it didn’t worked too,

I was wondering how to get the fix, so in my browser inspect window, i saw one selector [type=search] and some styles applying via _reboot.scss file, I tried to open that file from my application it was there, because I am using bootstrap, so its coming through that from node_modules dynamically maybe.

So in my main.scss, file where I was earlier adding css code for placeholder text “Search Author”) color to white, but it was still in dark grey color not taking effects

SCSS code

after I thought and tried to add the placeholder wrapping [type=search] selector it worked like a charm!

Finally worked, placeholder text color change to search type input field in HTML!!!

I hope you will get to learn from this simple issue and try to explore something own to figure out the issue we face.

Something some simple things are hard to figure out due to some companies work hard building great stuff making simple stuffs complicated to be fix later!

Anyways happy learning! Enjoy.

P.S

Later found simple text placeholder color text was not taking effect, maybe scss is not compiling the placeholder css code as default placeholder target selector, added below code to target text field, select and textarea individually and it started working for different parts of the application where used.

Categories
Learning Tech

Laravel; How to pull existing records on select change event using session type and date passed to dynamic web route in Laravel?

Welcome to Post,

Lets learn how to do the thing in the question, assuming you have basic or advance knowledge or learning something of your own to understand the things or you have got stuck due to simple issues of mistakes.

Using jQuery, HTML, Laravel Blade, Controller, Web Route and AJAX.

Lets begin.

Lets we talk first and defined about the HTML form field and its jQuery functionality. (I will be skipping middle parts of the code what it does and how its populated for the form fields ) and we will be using two fields here to show the example : session_date and session_type, which would look like below in the html code. session_type values would be morning, evening and so on for the day session.

<div class="row">
                            
                            <div class="form-group col-md-3">
                                <label for="session_date">Session Date:<sup>*</sup> </label>
                                <input type="date" name="session_date" id="session_date" class="form-control jsSessionDate" 
                                    value="{{ old('session_date', now()->format('Y-m-d'))}}"    
                                />
                                <!--<div class="text-end"><small class="text-muted"></small></div>-->
                            </div>
                            
                            <div class="form-group col-md-3">
                                <!--<input type="hidden" name="session_type" class="form-control hide mt-1" value="morning" />-->
                                                
                                <label for="session_type">Select Session Type:<sup>*</sup></label>
                                <select name="session_type" id="session_type" class="form-select text-capitalize jsSessionTypeChange" 
                                    >
                                    @foreach ($sessions_types as $ddSession)
                                        <option value="{{ $ddSession }}" {{old('session_type') ==  $ddSession ? 'selected' : ''}}>{{ $ddSession }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>

Once we have the basic fields ready in HTML side we can write the jQuery side of it to fetch the records and make the AJAX call our server side of Laravel Controller.

$(document).on('change', '.jsSessionTypeChange', function(e) {
                const { value } = e.target;
                const sessionDateVal = $('.jsSessionDate').val();
                console.log(value)
                
                if(!value) return;
                
                const $this = $(this);
                const payload = { 
                    _token:  $('meta[name="csrf-token"]').attr('content'),
                };
                
                const sessionType = value || 'morning';
                const sessionDate = sessionDateVal ?? {{now()->format('Y-m-d')}};
                
                const baseUrl = window.location.origin+'/ams';
                const url = `${baseUrl}/existing-session/${sessionType}/${sessionDate}`;
                    
                console.log({url, sessionType, sessionDate});
                
                $.ajax({
                    url,
        			type: "get",
        			cache: false,
                }).done(function(resp) {
                    if(resp) {
                          console.log({
                              resp
                          })
                    }
                   })
                   .fail(function(err) {
                     console.error("Existing session fetch  error: ", err, err.responseText);
                });
            });

//IGNORE THE CONSOLE LOGS

Here, I am getting values from date filed and select dropdown for session type, on session type change event forming server side api end point url, not using PHP Laravel Blade example with javascript is its very difficult for blade to understand passing dynamic javascript variable to it.

Because PHP code executed on the page load even we defining the blade {{ }} in onChange event function scope. so its looks for that variable and its goes undefined , tried otherways around the then get the error from rotue generation syntax as route is forming dynamically.

So I thought to set back with simple Javascript code for forming the base URL and its endpoint for ajax call to happen.

Giving you context what I said above and for what thing i was trying to do in Javascript of code using Laravel Blade syntax, which didn’t worked out simply.

Try 1:

const type = value || 'morning';
const url = "{{ route('existing-session', ['sessionType' => '${type}']) }}";

$.ajax({
    url: url,
    // ... rest of your AJAX configuration
});

Try 2:
const type = value || 'morning';
const url = "{{ route('existing-session', ['sessionType' => '${type}']) }}";

$.ajax({
    url: url,
    // ... rest of your AJAX configuration
});

Try 3: Finally
const type = value || 'morning';
const baseUrl = window.location.origin;
const url = `${baseUrl}/existing-session/${type}`;

$.ajax({
    url: url,
    // ... rest of your AJAX configuration
});

Okay, now our HTML and JQUERY code is ready, lets quickly add in to our routes/web.php, dynamic route for ajax to work!

// To get existing Session on Create View
Route::get('existing-session/{sessionType}/{sessionDate}', [App\Http\Controllers\EventSessionController::class, 'existingSession'])->name('existing-session');

Now Finally in Controller side, write as method to get the sessionType and sessionDate and pull it the data from database and return as json response to the ajax call. Then we are good to finish!

public function existingSession($sessionType, $sessionDate) {
    // Fetch session with today's date and specific session type

    if($sessionType  !== '' && $sessionDate !== '') {
        $existingSession = EventSession::with(['members', 'samagams'])->where('session_type', $sessionType)
        ->whereDate('session_date', $sessionDate ?? now()->format('Y-m-d'))
        ->first();

        $response = ["data" => $existingSession, "success" => true, "error" => false, "message" => $sessionType." session found for date ".$sessionDate];
    } else {
        $response = [ "data" => null, "success" => false, "error" => true, "message" => "No existing session found for given session type ". $sessionType ." and date " .$sessionDate];
    }

    return response()->json($response);
}

Voila, your quick AJAX example ready in Laravel with pulling in data with dynamic passing of data to the GET route.

Hope this gives you hints, idea how to do the things in PHP Laravel.

Thanks for reading the post and happy learning!

Categories
Tech

Show 3 cards next to each other and rest follow below similar, how should I write code in css using flex?

Hello,

To display 3 cards next to each other using CSS flex, you can use the flex-wrap property with a value of wrap, combined with the flex property to set the size of each card. Here is an example:

<div class="card-container">
  <div class="card">Card 1</div>
  <div class="card">Card 2</div>
  <div class="card">Card 3</div>
  <div class="card">Card 4</div>
  <div class="card">Card 5</div>
  <div class="card">Card 6</div>
  <div class="card">Card 7</div>
  <div class="card">Card 8</div>
  <div class="card">Card 9</div>
</div>

CSS:

.card-container {
  display: flex;
  flex-wrap: wrap;
}

.card {
  flex-basis: calc(33.33% - 10px); /* Set the width of each card to one-third of the container minus some margin */
  margin-right: 10px; /* Add some margin between the cards */
  margin-bottom: 10px; /* Add some margin below the cards */
  background-color: #f5f5f5;
  padding: 10px;
  box-sizing: border-box;
}

In this example, the card-container element is set to display: flex, which makes its child elements align horizontally in a row. The flex-wrap: wrap property allows the cards to wrap onto the next row when there isn’t enough space for them all to fit on one row. The flex-basis property is used to set the width of each card to one-third of the container minus some margin, and the margin-right and margin-bottom properties add some spacing between the cards. The box-sizing: border-box property ensures that the padding of each card is included in its width calculation.

Source: AI Interaction Channel

Happy Learning!

Categories
Blog Learning Learning

Picture tag in HTML

The <picture> tag in HTML is a semantic element that is used to define multiple source images for a single content. The <picture> element is used to specify multiple sources for an image, allowing the browser to choose the most appropriate source based on the user’s device and screen size. This allows you to display images that are optimized for different devices, without having to rely on JavaScript or CSS media queries.

Here’s an example of how you might use the <picture> tag:

<picture >
  < source srcset="large.jpg" media="(min-width: 800px)">
  < source srcset="small.jpg" media="(max-width: 799px)">
  < img src="small.jpg" alt="A picture">
</ picture >

In this example, the < source > elements define different sources for the image, based on the screen size of the user’s device. If the screen is at least 800 pixels wide, the browser will choose the large.jpg image, while if the screen is smaller than 800 pixels, it will choose the small.jpg image. The <img> element is used as a fallback for browsers that do not support the <picture> element.

hope you understand the basic concepts and use of Picture Tag in HTML

Source: AO Interaction Channel

Categories
Learning

What is the life cycle of an HTML request

Hello, Welcome

The life cycle of an HTML request can be divided into following stages:

  1. Request initiation: The request is initiated by the browser, usually in response to a user action, such as clicking a link, submitting a form, or refreshing the page.
  2. DNS Lookup: The browser checks the local cache and DNS servers to resolve the domain name to an IP address. If the domain name has not been resolved before, the browser will initiate a DNS lookup to obtain the IP address of the server.
  3. TCP Connection: The browser establishes a TCP connection with the server. This is the underlying communication channel that will be used to send the HTTP request and receive the response.
  4. Request sent: The browser sends an HTTP request to the server. The request includes information about the type of operation being performed (e.g., GET, POST, PUT, DELETE), the URL being requested, and any additional data that may be required (e.g., form data).
  5. Server processing: The server receives the request and processes it. This may involve retrieving data from a database, processing data, or generating a response.
  6. Response sent: The server generates an HTTP response and sends it back to the browser. The response includes information about the status of the request, the type of data being returned, and the actual data itself.
  7. Response received: The browser receives the response and processes it. This may involve updating the contents of the page, displaying an error message, or redirecting to another page.
  8. Resource loading: If the response includes references to additional resources (e.g., images, stylesheets, scripts), the browser will initiate separate requests for each of these resources.
  9. Page rendering: The browser uses the information in the response to render the final page.

This entire process can take place in a matter of milliseconds, allowing the user to interact with the web page in near-real-time.

Source: AI Interaction Channel

Happy learning!